Tutorials4u.net Forum

Full Version: Prevent caching of a JSP output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Reference URL's