如何改变这一个servlet流PDF文件到一个浏览器页面的标题? [英] How to change the title of a browser page which a servlet streamed a PDF to?

查看:893
本文介绍了如何改变这一个servlet流PDF文件到一个浏览器页面的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的基于Java的web应用程序有基于请求参数,它流PDF内容返回给浏览器的servlet。

My Java based webapp has a servlet which streams PDF content back to the browser based on request parameter.

例如。用户点击一个标签,对myApp / FetchPDFServlet?ID = 123的一个href。 Servlet映射拿起请求,PDF格式的数据流,以响应为MIME类型的应用程序/ PDF格式,关闭刷新缓冲区。

e.g. user clicks on an A tag with an href of "myApp/FetchPDFServlet?id=123". Servlet mapping picks up request, streams PDF data to response as mime-type application/pdf, closes flushes buffers.

不过,对于显示PDF页面的浏览器的标题栏显示为FetchPDFServlet?ID = 123

However the browser title bar for the page displaying the PDF reads "FetchPDFServlet?id=123"

如何更改标题,浏览器将显示该显示PDF页面?
所以浏览器的标题是这是惊人的PDF而不是FetchPDFServlet?ID = 123。

How can I change the title the browser displays for the page that displays the PDF? So the browser title is "Here is the amazing PDF" not "FetchPDFServlet?id=123".

是否有可能呢?如何最有效地做到这一点?

Is it possible at all? How best to do this?

推荐答案

这头添加到您的HttpServletResponse:

Add this header to your HttpServletResponse:

response.setHeader("Content-Disposition","inline; filename=Here is the Amazing PDF");

我认为浏览器将它捡起来,并把它作为窗口的标题。

I believe the browser will pick it up and use it as the title of the window.

这篇关于如何改变这一个servlet流PDF文件到一个浏览器页面的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆