tags:

views:

34

answers:

2

Hi, I´m programming Java App. and get an error, because browser dont connect to server to take new values, just renderize from cache... I make something like this:

<% if(request.getAttribute("msg")!=null)
    out.println("alert("+request.getAttribute("msg")+")");
%>

It works fine, but when i click on a link and then click on BACK button from browser it dont call server... I tried something like: response.setHeader("Pragma", "No-Cache"); on Java and on html, but nothing make it work... anyone have a suggest?

Thanks Regards Rodrigo

+1  A: 

Ensure your browser is set to request new pages every time you visit a site. You may also want to add a extra parameter to request like a time stamp so that it always looks like a new request to the server.

Kevin D
A: 

You indeed need to instruct the webbrowser to not cache the response by setting the appropriate response headers. The correct set of response headers are those:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.

You'd like to do this in a Filter class which is mapped on an url-pattern of interest, e.g. *.jsp rather than copypasting the same over all JSP pages.

See also:

PS: don't forget to clear the browser cache before testing, the old page might be still in there ;)

BalusC