1

I don't want the browser to cache a specified jsp, so I used the code below in my jsp:

<%
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
%>

However, it doesn't work. Everytime I press the back button, the browser shows the cached page without refreshing.

Does the position of the code in the jsp matter? How to disable the cache?

Neo
  • 169
  • 2
  • 4
  • 12

1 Answers1

7

A typo? Pramga instead of Pragma? Try.

<%        
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    response.setDateHeader("Expires", -1);
%>

EDIT: see this question How to control web page caching, across all browsers?

Community
  • 1
  • 1
Praveen Lobo
  • 6,369
  • 2
  • 23
  • 35
  • OK, I corrected that but found no use. Maybe it's browser matter? – Neo Jun 18 '11 at 15:22
  • I updated the answer, please try now. I got it from [here](http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers) – Praveen Lobo Jun 18 '11 at 15:29
  • This time it works, thanx! I don't even to set the browser anymore. – Neo Jun 18 '11 at 15:38
  • This accepted answer is dedicated to @BalusC. I see his answer everywhere for this type of question on SO. – Praveen Lobo Jun 18 '11 at 15:42