How to set RESPONSE Headers globally using J2EE container (Websphere)

自古美人都是妖i 提交于 2019-12-07 08:38:52

问题


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);

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


回答1:


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

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.


来源:https://stackoverflow.com/questions/1676953/how-to-set-response-headers-globally-using-j2ee-container-websphere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!