This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP Caching in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Caching in Tomcat" Watch "JSP Caching in Tomcat" New topic

JSP Caching in Tomcat

Scot Meyer

Joined: Feb 17, 2004
Posts: 12
I have a problem with caching in my new servlet. Currenly I am using Eclipse and Tomcat for development. I noticed that when I request a page the page is compiled and instantiated. The page would get data from the database and display it. I would then goto a new page to update the data expecting the prior page to display it differently. When returning to the original page (without using the back button) the value displayed is the previous one even though it was changed.
I believe this is something to do with caching. I used the praga/no-cache and Cache-control/no-cache headers without avail.
Is this something relating to the fact that the servlet eclipse generates does not contain a getLastModified function? If this is the case how would I go about fixing it? Thank you in advance
I used IE5.5 for testing
john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
Have you tried:
Scot Meyer

Joined: Feb 17, 2004
Posts: 12
I have not tried that. Wouldn't the user get a Page Expired message if they chose the back button? Not that this is not desireable. Is this the normal procedure for situations like this? I would have expected that a user requesting a page (servlet) would not be cached but reran.
[ March 15, 2004: Message edited by: Scot Meyer ]
Scot Meyer

Joined: Feb 17, 2004
Posts: 12
I just tried adding
<% response.setHeader("Cache-Control", "no-cache"); %>
<% response.setHeader("Cache-Control", "must-revalidate"); %>
<% response.setHeader("Pragma","no-cache"); %>
<% response.setDateHeader("Last-Modified",System.currentTimeMillis());%>
to my page response and this still didn't fix it. It's as though the servlet is not being called and the information is being cached in the web server. Is it possible that Apache is causing this?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63341

First step would be to verify whether your servlet is being called or not. Otherwise, we're just guessing.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Scot Meyer

Joined: Feb 17, 2004
Posts: 12
Ok did some additional testing. The JSP is definately not being called when the page is requested a second time. It will be called if I hit the Refresh button. So I am guessing this is an Apache setting. Currently my httpd.conf file states that the file_cache_module, headers_module, and cern_meta_modules are not loaded. Thank again for any help
I meant Tomcat 5.0 not Apache.
[ March 16, 2004: Message edited by: Scot Meyer ]
Scot Meyer

Joined: Feb 17, 2004
Posts: 12
Ok, I loaded all the source for tomcat and steped through the page. It appears as though if on a page reload(refresh) the code is called. I put a breakpoint at the earliest point in the tomcat source of the Http11 connector. This is a step after the thread is created.
Whats intereting is if I hit the enter key or retype the url in the address bar the page is not requested again even if I set the caching headers (in the above post). So it must be that IE doesn't resumit a request if it thinks the page is exactly the same (When it obviously isn't)
Im sure I am overlooking something obvious.
Madhan Ramalingam

Joined: Aug 22, 2002
Posts: 7
there also a IE setting that controls caching,
Internet Options -> temporary internet files -> settings -> check for newer versions of the stored page.
I agree. Here's the link:
subject: JSP Caching in Tomcat
jQuery in Action, 3rd edition