Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disable browser caching not working

 
felix thomas
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try disabling the back button...
 
felix thomas
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can u disable back button using servlets
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
felix thomas
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Thanx,
Felix
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
Regards
Maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic