This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark ""Refreshing" jsp" Watch ""Refreshing" jsp" New topic
Author

"Refreshing" jsp

Ed Lance
Ranch Hand

Joined: Aug 02, 2000
Posts: 38
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

Joined: Nov 21, 2000
Posts: 98
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

Joined: Aug 02, 2000
Posts: 38
Very clever.
Used the time stamp idea...it ROCKS!
Thanks
Nirban Dutta
Greenhorn

Joined: Jun 20, 2001
Posts: 9
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

Joined: Sep 11, 2000
Posts: 94
If you don't mind using javascript, do a location.reload
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "Refreshing" jsp
 
Similar Threads
how to get data from servlet to jsp
delete from slecet box
Data of previous form gets submitted on refersh
B&S: Which Exceptions to be shown to user?
Passing parameters from jsp to servlet