Prevent caching of a JSP outputTag(s): Servlet/JSP


You will need to set the appropriate HTTP header attributes.
<%
response.setHeader("Cache-Control","no-cache"); 
response.setHeader("Pragma","no-cache"); 
response.setDateHeader ("Expires", -1); 
%>

However, cache handling is tricky with IE brower.

See http://support.microsoft.com/kb/q222064/.

By adding a second HEAD is supposed to solve the problem!

<%
response.setHeader("Cache-Control","no-cache"); 
response.setHeader("Pragma","no-cache"); 
response.setDateHeader ("Expires", -1);
%>
<HTML>
<HEAD> 
</HEAD> 
<BODY>
my page body

</BODY>
<HEAD> 
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD> 
</HTML>
NOTE: Pragma: no-cache prevents caching only when used over a secure connection, Expires: -1 should do the job over unsecure conection.

See also this HowTo and this one.


blog comments powered by Disqus