File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes prevent page caching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "prevent page caching" Watch "prevent page caching" New topic

prevent page caching

James Hoare

Joined: Aug 11, 2006
Posts: 9
I have a problem with one of my pages caching and I need a way of preventing this. I have tried adding the following to the page, but it doesn't prevent caching in IE or FF?

response.setDateHeader ("Expires", -1);

The problem I have is that when a user clicks on the back button in the browser the form details are still present, I would like to prevent this.

Please can you help.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The web app has no control over what the browser does upon clicking the back button. Most of the times, the browser will re-display its cached version of the previous page, no matter what the cache settings are. That's just how the Back button works.

What problem does that present to your application? There may be ways to prevent any possible negative side effects.
James Hoare

Joined: Aug 11, 2006
Posts: 9
Thanks for the quick response. The problem is that the details cached are credit card details, therefore ideally I would like the information removed from the form if the back button is used.
Lauri Lehtinen

Joined: Oct 11, 2007
Posts: 1

I struggled with a pretty much identical case a while ago - I found no way of preventing the browser of caching a page and letting the user access it by clicking on the Back button, even after they had logged out. I was looking at the headers set by my Internet bank site and some webmails, until I realised it was the use of https that did the trick. I wasn't using https on my development machine, which caused the confusion. Since you're handling credit card info, I'd assume you'll be using https in production as well?
I agree. Here's the link:
subject: prevent page caching
It's not a secret anymore!