I want to disable the cache for a JSP file on my google app engine website.
I have this:
<%
// Set to expire far in the past.
response.setHeader("Expires", "Sat, 6 May 1995 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");
%>
But the JSP is still in cache. I need to kill the user session and login again in order to reload the JSP code.
How do I disable the cache for a app engine JSP?
It might at that point be too late to change the response headers. They will simply be ignored. You can verify the presence of response headers in a HTTP debugger tool like Firebug.
In the JSP, you need to ensure that they are set before the response is committed (i.e. all headers are already sent; you cannot send another headers afterwards). I.e. ensure that they are in the very top of the JSP file and that no template text is before that piece of scriptlet. Template text may cause a commit of the response. The normal practice, however, is to use a
Filter
for this.Implement
javax.servlet.Filter
whereindoFilter()
method look like follows:Map this in
web.xml
on anurl-pattern
of*.jsp
and it ought to work.See also: