2012-03-01 34 views
0

我們希望Web服務器中包含敏感內容的所有響應返回下面的HTTP頭:禁用瀏覽器緩存中的Tomcat 6

Cache-control:no-store 
Pragma:no-cache. 

我們使用Tomcat服務器版本6.0。

請建議我們必須在哪裏進行更改。這樣

+1

http://stackoverflow.com/questions/2563344/how-to-add-response-headers-based-on-content-type-getting-content-type- before-t – Mikaveli 2012-03-01 14:52:28

回答

1

Servlet過濾器應該有所幫助:

public class ResourceCacheFilter implements Filter { 
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 
     HttpServletResponse res = (HttpServletResponse) response; 
     res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); 
     res.setHeader("Pragma", "no-cache"); 
     chain.doFilter(request, response); 
    } 
} 
+0

當我添加了這個並在web.xml中添加了過濾器url映射。但 <濾波器映射> myClientapp /* <濾波器映射> CacheManagerFilter * .jsp ' 這是造成問題的原因。當我添加過濾管理器的所有頁面變爲空白,如果我刪除,那麼它將加載頁面。如何解決這個問題? – Sadanand 2014-05-22 04:17:26