tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Funk <>
Subject Re: Client-side caching via If-Modified-Since
Date Wed, 08 Sep 2004 13:21:03 GMT
There is no need for the response's last modified header. Unless you wish to 
set a header in the caching response header. But at that point - that is your 
code setting it, not tomcat.

If a client is sending a If-Modified-Since header - that means they have 
retrieved the content at some time. In that case, you'd need a rule to 
determine when to re-display page or send a 304. (The job of the filter).

Your original code is
- Executing the JSP (and probably sending content back to the client)
- Then checking for freshness and possibly sending a 304
- At which point - you probably are getting an IllegalStateException

Unless your page is smaller than the buffer size - I bet you'll see a lot of 
IllegalStateExceptions in your logs.


Joost Baaij wrote:

> Thanks for your help! A filter then.
> it's the question "if(contentIsFresh)" I'm having trouble with.
> I can getDateHeader(If-Modified-Since) from the request without any
> problems, but how can I retrieve the Last-Modified from the response?
> There's no method for it. Does the initial request-object have this
> information?
> I'm a novice servlet programmer. Sorry if my question is too basic.
> Also, I do think the chain.doFilter() must still be executed. I need to
> get that Last-Modified information from the response (if only I knew how
> to access it!)
> Joost.
> On Wed, 8 Sep 2004, Tim Funk wrote:
>>It belongs in a filter like you have done. It doesn't belong in tomcat.
>>Also your filter isn't correct - it is still executing your JSP code and 
>>wasting resources. It should be:
>>doFilter() {
>>   ...
>>   if (contentIsFresh) {
>>     httpResponse.sendError(HttpServletResponse.SC_NOT_MODIFIED);
>>   } else {
>>     chain.doFilter( ... );
>>   }

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

View raw message