简体   繁体   English

使用java servlet api删除http标头

[英]Remove http header using java servlet api

We are using IBM Websphere Application Server 6.1 and browser is Internet Explorer 8. 我们使用的是IBM Websphere Application Server 6.1,浏览器是Internet Explorer 8。

We have a java servlet which dynamically generates PDF and MS Word documents. 我们有一个java servlet,它可以动态生成PDF和MS Word文档。 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." “Internet Explorer无法打开此站点。请求的站点不可用或无法找到。请稍后再试。”

As per Microsoft Support article id 323308 根据Microsoft支持文章ID 323308
When you try to open a Microsoft Office document or a PDF document over HTTPS (SSL) IE fails with above error message. 当您尝试通过HTTPS(SSL)IE打开Microsoft Office文档或PDF文档时,IE失败并显示以上错误消息。 This issue occurs if the server sends a "Cache-control:no-store" header or sends a "Cache-control:no-cache" header. 如果服务器发送“Cache-control:no-store”标头或发送“Cache-control:no-cache”标头,则会出现此问题。 For IE8 Microsoft suggests to add registry entry on users Windows XP desktop. 对于IE8,Microsoft建议在用户Windows XP桌面上添加注册表项。 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. 这不会发生在IE9,Firefox,Chrome等上。

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. 根据PK20531 ,当响应中设置了cookie时,WAS 6.1正在添加Cache-Control:no-cache =“set-cookie,set-cookie2”和Expires HTTP标头。

Note - We are not setting the cookie in the servlet. 注 - 我们没有在servlet中设置cookie。 The cookie is set by single sign-on software. Cookie由单点登录软件设置。

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. 在第一次尝试设置单点登录(LTPA)cookie并且WAS正在添加IE浏览器不喜欢的HTTP标头时。

Does Java servlet api provide a way to remove http headers? Java servlet api是否提供了删除http标头的方法? Is there a technique to use Filter api to remove http headers? 是否有使用Filter api删除http标头的技术?

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. 如果从响应中删除Cache-Control标头,那么您不会发送有关缓存的任何指令,因此缓存行为将是不可预测的。

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: 因此,您可以将这些行添加到servlet中以在浏览器中启用缓存:

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. 您也可以在Filter执行此操作,因为过滤器可以访问HTTP响应对象。 But if you've written your own servlet then it's probably more efficient — and clearer — to do it in the servlet. 但是如果你已经编写了自己的servlet,那么在servlet中执行它可能会更有效 - 也更清晰。

It's all controllable by you. 这一切都是你可以控制的。 If you don't put it there, there will be nothing to remove. 如果你不把它放在那里,就没有什么可以删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM