The moose likes Servlets and the fly likes disable browser caching not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "disable browser caching not working" Watch "disable browser caching not working" New topic

disable browser caching not working

felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
I have a application made on servlets mainly,but i use xslt for display purpose.If any user make any entry in the application he can use the back button of browser to go to periovus page and redo the entry, i want to disable that, is there any whay i can disable the chache in browser.

i used the following line also.
but not working
// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");

// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
response.addHeader("Cache-Control", "post-check=0, pre-check=0");

// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
please help
Basavaraju Banakar

Joined: Jul 18, 2002
Posts: 25
try disabling the back button...

It is impossible to make anything foolproof because fools are so ingenious..Murphy<br />Basu.
felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
how can u disable back button using servlets
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Realistically, there is no way you can guarantee that a user will never resubmit an old form. Even if you disable the "back" button, there's usually a context menu option to go back, or the user can bookmark the form page and go back to the bookmark, or type in a "javascript" URL, etc. etc.
A much more robust solution is to track on the server which forms have been submitted. Generate some sort of "transaction id", and pass it to the browser as a hidden form parameter. Then when the form is submitted, before it is procesed on the server, check on the server whether that id has already been received and dealt with.
If you take this approach you can let the user be free to configure his/her own browser, and you can issue a friendly warning message if a form is submitted more than once.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
Mr Frank,
Could u show me an example or code on how to check the transaction id on server.I understood the concept but cannot understand how to implement it,
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Hi felix
My 2 cents..
If we go with suggestion brought up by Frank, then we would have to,
- store all the submissions for a while for transaction id
- also, it depends on what we choose as transaction id. for e.g. if we have chosen a user name that logged in then we have to make sure that we remove the transaction id from our "submitted requests" table as we want user to submit the form again in future. I hope I am able to convey my thoughts here.
so in essence we can choose any mechanism for the transaction id but we have to make sure of certain things about managing it depending upon our application context/requirements..
Also, there are many disucussions about how to disable back button on Javaranch. So you can look for them if you wanted to dig into details about approaches/issues...
I agree. Here's the link:
subject: disable browser caching not working
It's not a secret anymore!