-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Siros Supavita
Sent: Sunday, November 07, 1999 7:51 PM
To: [EMAIL PROTECTED]
Subject: How to prevent Page Caching by Servlet ??Hello,
I have a problem with page caching on Web Browser. I write a servlet to serve as "dispatcher" to various resource on my web server. Problem is when I forward request to static html page, it's cached on web browser and next time I refer to that link (the same URL but another situation , checking by using cookie, should result in different page) but it's still the old page. Here is example of my code.
HttpSession session = request.getSession(false);
if (session == null) {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/home/index.html");
dispatcher.forward(request,response);
} else {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/protected_area/protected.html");
dispatcher.forward(request,response);
}URL of this Servlet is "/servlet/Dispatcher" ... When I first access this servlet it results in "/home/index.html" which is correct. But after I gain Session from web server and access this servlet again (which should result in "/protected_area/protected.html") ... the index page appear (if I clear cache on browser and try again ... it work)... I tried set this header on the starting of the Servlet to make it expired.
Date thisTime = new Date();
response.setDateHeader("Date",thisTime);
response.setDateHeader("Expires",thisTime);It worked ... the servlet execute everytime I request the URL ... but page "protected.html" didn't appear yet !!! ... I checked it and saw that the last modified time of index.html is newer than protected.html. I think web browser remember the last modified of the URL and check if the server content is older than the one it has ... it uses its own , Right ??
Then I have to make browser not to remember anything about the server content (say no caching ... ). I know that set header in response may help .. but WHICH ONE IS TO BE SET ??
Every comment and suggestion is welcome, Thank you
Siros
Title: How to prevent Page Caching by Servlet ??
How
about setting the header of the page to a date earlier than the date in
protected.html?
A nicer way to solve this would be make the date
returned by the Servlet newer than that of the html, by implementing the
doHeader() method in the Servlet. See Servlet API for
details...
hope
that helps,
Arno
- How to prevent Page Caching by Servlet ?? Siros Supavita
- HELP!!! Marvin Garcia
- Re: How to prevent Page Caching by Servlet ?? Tobias J�rlund
- Re: How to prevent Page Caching by Servlet ?? Michal Mosiewicz
- Re: How to prevent Page Caching by Servlet ?? Arno Schatz
- Re: How to prevent Page Caching by Servlet ?? Siros Supavita
- Re: How to prevent Page Caching by Servlet ?? Milt Epstein
- Re: How to prevent Page Caching by Servlet ?? George Ter-Saakov
- Re: How to prevent Page Caching by Servlet ?? pradeep paudyal
- Re: How to prevent Page Caching by Servlet ?? Anupindi, Ravikiran
- Re: How to prevent Page Caching by Servlet ?? DeepaN
