使用 java servlet api 删除 http 标头
我们使用 IBM Websphere Application Server 6.1,浏览器是 Internet Explorer 8。
我们有一个 java servlet,可以动态生成 PDF 和 MS Word 文档。在第一次尝试时,一些用户表示他们收到
“Internet Explorer 无法打开此站点。请求的站点不可用或无法找到。请稍后再试。”
根据 Microsoft 支持文章 ID 323308
当您尝试通过 HTTPS (SSL) 打开 Microsoft Office 文档或 PDF 文档时,IE 失败并显示上述错误消息。 如果服务器发送“Cache-control:no-store”标头或发送“Cache-control:no-cache”标头,则会出现此问题。 对于 IE8,微软建议在用户 Windows XP 桌面上添加注册表项。这对我们来说不太实际,因为我们无法控制用户桌面。对于 IE9、Firefox、Chrome 等,不会发生这种情况。
注意 - 我们没有在 servlet 中设置 cookie。 cookie 由单点登录软件设置。
第一次尝试时,当设置单点登录 (LTPA) cookie 时,WAS 添加了 IE 浏览器不喜欢的 HTTP 标头。
Java servlet api 是否提供了删除 http 标头的方法?有没有一种技术可以使用 Filter api 来删除 http 标头?
We are using IBM Websphere Application Server 6.1 and browser is Internet Explorer 8.
We have a java servlet which dynamically generates PDF and MS Word documents. On the first attempt some users are saying they are getting
"Internet Explorer was unable to open this site. The requested site is either unavailable or cannot be found. Please try again later."
As per Microsoft Support article id 323308
When you try to open a Microsoft Office document or a PDF document over HTTPS (SSL) IE fails with above error message.
This issue occurs if the server sends a "Cache-control:no-store" header or sends a "Cache-control:no-cache" header.
For IE8 Microsoft suggests to add registry entry on users Windows XP desktop. This is not very practical for us to do as we don't control our users desktops. This does not happen for IE9, Firefox, Chrome, etc.
As per PK20531 WAS 6.1 is adding Cache-Control: no-cache="set-cookie, set-cookie2" and Expires
HTTP headers when there is cookie being set in the response.
Note - We are not setting the cookie in the servlet. The cookie is set by single sign-on software.
On the first attempt when the single sign-on (LTPA) cookie is being set and WAS is adding HTTP headers which IE browser does not like.
Does Java servlet api provide a way to remove http headers? Is there a technique to use Filter api to remove http headers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从响应中删除
Cache-Control
标头,则您不会发送任何有关缓存的指令,因此缓存行为将是不可预测的。最好将标头设置为其他内容,而不是删除它。大概您想在浏览器上为您的页面启用缓存。因此,您可以将这些行添加到您的 servlet 以在浏览器中启用缓存:
您也可以在
Filter
中执行此操作,因为过滤器可以访问 HTTP 响应对象。但是,如果您编写了自己的 servlet,那么在 servlet 中执行此操作可能会更有效且更清晰。If you remove the
Cache-Control
header from the response, then you're not sending any instructions about caching and therefore the caching behavior would be unpredictable.It would be better to set the header to something else, rather than remove it. Presumably you want to enable caching on the browser for your pages. So you could add these lines to your servlet to enable caching in the browser:
You could do this in a
Filter
too, because filters have access to the HTTP response object. But if you've written your own servlet then it's probably more efficient — and clearer — to do it in the servlet.这一切都由你掌控。如果你不把它放在那里,就没有什么可以删除的。
It's all controllable by you. If you don't put it there, there will be nothing to remove.