aspose file tools*
The moose likes General Computing and the fly likes how to avoid caching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "how to avoid caching" Watch "how to avoid caching" New topic
Author

how to avoid caching

saran sadaiyappan
Ranch Hand

Joined: Dec 23, 2004
Posts: 39
Hi all,
I want the caching facility of the browser to be disabled.i.e even after clicking the back button in the browser he should not be taken back but the message "page expired" to be displayed.Can anyone help me?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

This can't be controlled from the server side... it has to be done in the browser.

Moving to the general computing forum.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Rigel Kentaurus
Greenhorn

Joined: Feb 09, 2005
Posts: 11
Originally posted by saran sadaiyappan:
Hi all,
I want the caching facility of the browser to be disabled.i.e even after clicking the back button in the browser he should not be taken back but the message "page expired" to be displayed.Can anyone help me?


Use this code in every servlet:

response.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");

No waranty, but the browser is sent the instruction of not storing in the cache that page
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to avoid caching