Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to disable browser caching with jsp

 
Stephen Peterson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
In a class, I was told to execute the following code in order
to disable browser caching:
res.setHeader("Pragma", "no-cache");
res.setHeader("Cache-Control", "no-cache");
res.setdateHeader("Expires", 0);
I can see how I could do this if programming with servlets.
But how is this done when using JSP pages?
The reason I want to disable caching is to prevent the user from
getting into an incorrect application state by using the back-button to post a request from a stale browser page. I've seen jsp applications that always say the page has expired when the backbutton is pushed.
thanks
------------------
United Health Group
Hartford, CT, USA
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an implicit response object in JSPs, so just add this:

Dave.
[This message has been edited by David O'Meara (edited December 10, 2001).]
 
Stephen Peterson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,
Thanks for your reply. I tried your suggestion. I updated
my JSP file, between the <head> and </head> tags. The only change I needed was to change
response.setdateHeader("Expires", 0);
to
response.setDateHeader("Expires", 0);
before it was compiled okay.
However, the browser back-button still brings back the prior page content, just as before. I'm certain I'm using the updated JSP page because I made a small change in the title string which is showing up in the browser. What should I look at next?
What do people usually do to solve this problem?
thanks in advance!
[This message has been edited by Stephen Peterson (edited December 10, 2001).]
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been discussed at length in the HTML forum on javaranch.
I believe the best solution is to accept that back does whatever the browser wants, and simply assign each page view a transaction id so that you can track where the user should be (so that, for example, they cannot submit the same order twice).
James
 
Stephen Peterson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
james, you are right. In the html and javascript forum I did a search for back button and got 29 hits. My apologies to all, and thanks for the suggestion to look there.
The transaction id idea sounds intriguing. Since you mentioned it, can you point me to any good sources for examples of implementing this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic