Stop page caching in J2EE





4
Date Submitted Mon. Mar. 6th, 2006 5:03 AM
Revision 1 of 1
Scripter TimYates
Tags J2EE | JSP | no-cache
Comments 0 comments
This should stop your JSP page being cached by browsers and proxies.

It tries to cover all bases, just stick it at the top of any JSP page.

If your entire web application requires this, it would be much more economical to write a J2EE Filter, and run this code for each request before chaining on to the next filter..

<%
        // Set to expire far in the past.
        response.setHeader("Expires", "Sat, 2 May 1992 12:00:00 GMT");
        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
%>
 

Tim Yates

Comments

There are currently no comments for this snippet.

Voting

Votes Down