0

We want the web server to return the following http headers in all responses containing sensitive content:

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

We are using tomcat server 6.0 version.

Please suggest where we have to make changes.

skaffman
  • 398,947
  • 96
  • 818
  • 769
user735566
  • 471
  • 2
  • 5
  • 6
  • 1
    http://stackoverflow.com/questions/2563344/how-to-add-response-headers-based-on-content-type-getting-content-type-before-t – Michael Mar 01 '12 at 14:52

2 Answers2

1

Servlet Filter like this should help:

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);
    }
}
alexkasko
  • 4,855
  • 1
  • 26
  • 31
  • When I added this and added filter url mapping in web.xml. but myClientapp /* CacheManagerFilter *.jsp ` this is causing problem. when I add filter manager all pages become blank, if i remove then it will be load the pages. how to resolve this issue ? – Sadanand May 22 '14 at 04:17
0

Depending on your security constraint you can setup tomcat valve to have securePagesWithPragma to true (default) which would set the headers as you requested. please refer to Tomcat6 Valve Documentation for further details and also Tomcat: Cache-Control

Community
  • 1
  • 1