1

I´m programming Java App. and get an error, because browser don't 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 <meta http-equiv="expires" content="no-cache"> on html, but nothing make it work... anyone have a suggest?

Devin Burke
  • 13,074
  • 11
  • 51
  • 80
  • I am not sure why you used the `javascript` tag, but this is **definitely** not JavaScript. You're exposing a JSP *scriptlet* which is printing a JS alert (*scriptlets* should by the way be [avoided](http://stackoverflow.com/questions/3177733/howto-avoid-java-code-in-jsp-files) as much as possible). So I replaced the `javascript` tag by `jsp` one. – BalusC Oct 08 '10 at 19:28

2 Answers2

1

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
  • 3,484
  • 1
  • 17
  • 37
0

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 ;)

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452