使用 java servlet api 删除 http 标头

发布于 2024-11-26 21:02:10 字数 965 浏览 1 评论 0原文

我们使用 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 等,不会发生这种情况。

根据 PK20531< /a> WAS 6.1 正在添加 Cache-Control: no-cache="set-cookie, set-cookie2" 和 Expires 当响应中设置了 cookie 时的 HTTP 标头。

注意 - 我们没有在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下伊人醉 2024-12-03 21:02:10

如果您从响应中删除 Cache-Control 标头,则您不会发送任何有关缓存的指令,因此缓存行为将是不可预测的。

最好将标头设置为其他内容,而不是删除它。大概您想在浏览器上为您的页面启用缓存。因此,您可以将这些行添加到您的 servlet 以在浏览器中启用缓存:

response.setHeader("Pragma", "cache");
response.setHeader("Cache-Control", "private, must-revalidate");

您也可以在 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:

response.setHeader("Pragma", "cache");
response.setHeader("Cache-Control", "private, must-revalidate");

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.

情绪失控 2024-12-03 21:02:10

这一切都由你掌控。如果你不把它放在那里,就没有什么可以删除的。

It's all controllable by you. If you don't put it there, there will be nothing to remove.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文