Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

Prevent servlet response from being cache

 
Angel J Gama
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi!
This might be an old-school question, but I've just got stuck with this issue, and I'm not sure what would be the best practice for my scenario :S

Here is the thing:
1) I've a main page where the user can check his records ("/panel.jsp"), but the link to retrieve those records before accessing that page is "/servlet/panel.do?lang=en"
2) So, this servlet retrieves the records from the database and save them into a request attribute. Therefore, I use to goto the main page an populate it with the records in the request attribute.

But whenever I goto the servlet link, I get the same old data, no matter if the user inserted new info (the same old-school cache problem)

- I know that a solution would be to add the timestamp in the servlet link (ex: /servlet/panel.do?lang=en&836135165871). But I use this link in many pages. So, what would happen if, later on, I add this link in more pages and I forgot to add/create this timestamp param? I'll get the same old data. That's why I think this is not the way to do it in this scenario. I think that the timestamp practice is good for ajax stuff, isn't it?

- Another solution for this scenario would be to add tag in every page I don't want to be cache, but I've read that firefox has some problems with this tag. I'm not sure about safari. Am I wrong?

- Since I'm using a requestDispatcher, I can't use . Is there any other thing I can do in the servlet to prevent from being cache?


What would be the best practice to avoid/prevent the response from being cache?
Thanks a lot!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
The timestamp or random number is a well known hack. And this is really just an issue for IE. I'm not aware of firefox having issues with no-cache however. Do you have a reference to this info? Make sure you include all of these:



Note the pragma is IE only.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
    Bookmark Topic Watch Topic
  • New Topic