tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony LaPaso" <>
Subject Using JSPs to Send NOT-MODIFIED-SINCE Header
Date Tue, 04 Jun 2002 07:23:59 GMT
Hi all,

In looking at past posts, I'm afraid I know the horrible answer
to this issue but I thought I'd ask just in case I missed

Let me start by saying I'm using Tomcat v4.0.4 beta 3.

As you know, when a client (usually a web browser) has a cached
version of a resource (usually a web page) it can send an
"If-Modified-Since" header to the HTTP server. The server
compares the time/date stamp specified in the header with that of
the requested resource. If the resource has *not* been modified
since the time specified in the "If-Modified-Since" header, the
server sends back a 304 (Not-Modified) response, effectively
telling the client (usually a web browser) that its cached
version of the resource is still valid.

When writing a servlet, it's easy to handle this sort of
scenario. The javax.servlet.http.HttpServlet class has a
"service()" method. This method first checks if the incoming HTTP
method is a GET. If it is, the "service()" method proceeds to
call the "getLastModified()" method of the servlet. As a
developer, you can override "getLastModified()" to return a long
value representing the last time the requested resource was
changed. Depending on the value returned by "getLastModified()"
(note that -1 is returned if you don't override the method) the
"service()" method may simply return a 304, Not-Modified response
rather than calling the servlet's "doGet()" method.

Now, the $18.32 Question: How do you ensure "getLastModified()"
is called in JSP?

No, you cannot simply do this:

   public long getLastModified() {
      return xxx;

The problem is that the above method will never be called by the

I traced through some of the Tomcat/Catalina/Jasper code and it
seems to me that the response code is being set to 200/OK very
early on in the processing.

I also took a cursory look at the JSP spec and didn't find any
indication of setting a "Not-Modified" response, I am
thinking this is something that is (strangely) missing in the JSP
specification. I have a JSP page that needs to update itself once
per day. Therefore, it would be very handy to have the
"getLastModified()" functionality enjoyed by servlet writers.

Can anyone confirm this?


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message