Neo
Neo

Reputation: 169

Unable to disable jsp cache

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?

Upvotes: 1

Views: 18201

Answers (1)

Praveen Lobo
Praveen Lobo

Reputation: 7187

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?

Upvotes: 8

Related Questions