1

I've a Jsp that returns this html 5:

<html>
    <head>
        <title>Application</title>
        <!-- Some script includes here -->
    </head>
    <body>
        <!-- My html here -->
    </body>
</html>

At the moment the user need to disable caching into the browser, else the old page is reloaded every time.

I tried to force no-caching with a scriptlet in that way, but without success:

<%
response.addHeader("Cache-Control","no-cache");
response.addHeader("Expires","-1");
response.addHeader("Pragma","no-cache");
%>

Asde the fact the scriptlet wouldn't be a good solution, is there any way that works in JSP to disable caching?

user1883212
  • 7,539
  • 11
  • 46
  • 82

3 Answers3

1
Cache-Control

The above header must be a cross browser one.Might that causing problems

Try

response.addheader('Cache-Control: no-cache, no-store, must-revalidate');
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

If you are using Apache Tomcat change context.xml

<Context cachingAllowed="false">

You can read the documentation at http://tomcat.apache.org/tomcat-6.0-doc/config/context.html which says for

cachingAllowed

If the value of this flag is true, the cache for static resources will be used. If not specified, the default value of the flag is true.

AurA
  • 12,135
  • 7
  • 46
  • 63
  • is there something similar in jboss? – user1883212 Sep 24 '13 at 13:24
  • @user1883212 I have n't really worked much on jboss but hope you find https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/Administration_And_Configuration_Guide/jbosscache.chapt.html link useful. – AurA Sep 25 '13 at 04:50
0

Given you are using jsp files you are running this in a web container. We do this by using a javax.servlet.Filter to set the header values.

I don't know of any open sources filters that already do this but it is not that difficult to write yourself.

The headers we set for HTTP/1.0:

httpResponse.setDateHeader("Expires", 0L);
httpResponse.setHeader("Pragma", "no-cache");

The headers we set for HTTP/1.1:

httpResponse.setHeader("Cache-Control", "private,no-store,no-cache");
tom
  • 2,735
  • 21
  • 35