• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Refreshing" jsp

 
Ed Lance
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to reuse several forms in my application, one in particular is giving me a problem. I have a jsp that presents a list of users and one control on this page allows me to delete a user.
I use javascript to confirm the delete process, then set window location to a servlet. The servlet deletes the record from the database everytime and then calls the original jsp (so that you can see the user has been deleted from the list). I have tried using RequestDispatcher and response.sendRedirect from the servlet...but have one issue...if I delete two records in a row, the second time back to the jsp page, the (second) user still appears in the list. It is definitely being deleted in the database, and I have tried using a couple of the methods to ensure the page doesn't use the cache.
Any ideas?
Thanks!
 
manav kher
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no sure shot solution to prevent a client from caching your jsp's (damn microsoft traded performance for full implementation of the standards)
the only real solution is to change the url (the page will be pulled from cache anytime the url is the same as that of the cached page) so do something like this http://www.whatever.com/jsps/myJsp.jsp?someVar="random number"
and just ignore the variable someVar...but remember this to create unique url's every time u have to use some kinda random generation (or use a time stamp instead)
do that and the browser will be foxed into getting the page from the server and not from the cache.

did this make any sense...
manav
 
Ed Lance
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very clever.
Used the time stamp idea...it ROCKS!
Thanks
 
Nirban Dutta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
For preventing this problem,
add the following two line at the starting of ur jsp scripting in the jsp page
<%
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Expires","0");
%>
I am sure this will fetch the new updated copy of ur jsp every time.
 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't mind using javascript, do a location.reload
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by manav kher:
there is no sure shot solution to prevent a client from caching your jsp's (damn microsoft traded performance for full implementation of the standards)
the only real solution is to change the url [...]

Seconded. I did a financial forecasting intranet application a while ago and ran into the same problem. You really don't want to be looking at yesterday's data.
I tried everything else before resigning to this - all HTTP headers that could be halfway relevant (Pragma, Cache-Control, Expires, Last-Modified) and their META equivalents, it just didn't fully solve the problem. Only including a dummy timestamp in the URL completely eliminated caching.
- Peter

[This message has been edited by Peter den Haan (edited June 27, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic