如何使用J2EE容器(Websphere)全局设置RESPONSE标头 [英] How to set RESPONSE Headers globally using J2EE container (Websphere)

查看:209
本文介绍了如何使用J2EE容器(Websphere)全局设置RESPONSE标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Web服务器级别(web.xml)为所有事务设置标头?具体来说,我想这样做:

Is there a way, at the web server level (web.xml) to set headers for all transactions? Specifically, I would like to do this:

response.setHeader("Cache-Control", "no-cache, no-store");
response.setDateHeader("Expires", -1);

。我似乎记得可以在Web.xml中设置标头。还有其他解决方案吗?

at the application level. I seem to recall that headers could be set in the Web.xml. Are there other solutions?

推荐答案

实现 javax.servlet.Filter ,在 doFilter()方法中编写适当的逻辑,最后在上将其映射到 web.xml > url-pattern / *

Implement a javax.servlet.Filter, write appropriate logic in doFilter() method and finally map it in web.xml on an url-pattern of /*.

顺便说一下,'魔术' 'set在所有已知的浏览器和代理中都有效:

By the way, the 'magic' set which works in all known browsers and proxies are those:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.

这篇关于如何使用J2EE容器(Websphere)全局设置RESPONSE标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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