You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tony LaPaso <tl...@attbi.com> on 2002/06/04 09:28:03 UTC

??? Using JSPs to Send Not-Modified-Since Header ???

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
anything.

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
container.

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 code...so, 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?

Thanks...


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ??? Using JSPs to Send Not-Modified-Since Header ???

Posted by Tony LaPaso <tl...@attbi.com>.
Yes, but I'd prefer not to muck w/HttpJspBase -- as you said, it
is Tomcat specific.

I was hoping ther would be a more "portable", "approved"
way...but it looks like the JSP spec does not yet support it.
Really too bad -- getLastModified() was a big win.


----- Original Message -----
From: "Carlos Ferreira" <ca...@gilem.com>
To: <to...@jakarta.apache.org>
Cc: <tl...@attbi.com>; <se...@java.sun.com>;
<js...@java.sun.com>
Sent: Tuesday, June 04, 2002 10:33 AM
Subject: Re: ??? Using JSPs to Send Not-Modified-Since Header ???


>
> a not so good solution would be to subclass
> org.apache.jasper.runtime.HttpJspBase ( or redesign it ) with
your
> required behaviour and extend your jsp pages from this new
class.
> the problem is that HttpJspBase is tomcat specific. perhaps
somebody has a
> better idea.
>
> Carlos Ferreira
> Gilem Informatique
>
> > 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
> > anything.
> >
> > 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
> > container.
> >
> > 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 code...so, 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?
> >
> > Thanks...
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org> For
additional
> > commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ??? Using JSPs to Send Not-Modified-Since Header ???

Posted by Carlos Ferreira <ca...@gilem.com>.
a not so good solution would be to subclass
org.apache.jasper.runtime.HttpJspBase ( or redesign it ) with your
required behaviour and extend your jsp pages from this new class.
the problem is that HttpJspBase is tomcat specific. perhaps somebody has a
better idea.

Carlos Ferreira
Gilem Informatique

> 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
> anything.
>
> 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
> container.
>
> 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 code...so, 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?
>
> Thanks...
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org> For additional
> commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ??? Using JSPs to Send Not-Modified-Since Header ???

Posted by Tony LaPaso <tl...@attbi.com>.
Well, simply inserting a "getLastModified()" method into the generated
servlet will not work due to the class inheritance involved.

With standard (non-JSP generated) servlets, the "service()" method in
HttpServlet calls "getLastModified()". With JSP-based servlets,
HttpServlet's "service()" method has been overriden by Tomcat (i.e.,
Catalina stuff) so the call to "getLastModified()" does not occur.

Still, it might be possible to hack the JSP-based servlet....I hate to hack
though....

I'll think about it. Thanks for the suggestion.

Tony



----- Original Message -----
From: "Markus Kirsten" <ma...@iped.vxu.se>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, June 04, 2002 5:16 AM
Subject: Re: ??? Using JSPs to Send Not-Modified-Since Header ???


> Hi Tony,
> Isn't it possible to put in the method after the jsp file has been
> rewritten (by Tomcat) to a standard java source code file? Maybe it's
> quick and dirty but I can't see why it shouldn't work.
>
> Best of luck!
>
>
> Markus
>
> On Tuesday, June 4, 2002, at 09:28 AM, Tony LaPaso wrote:
>
> > 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
> > anything.
> >
> > 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
> > container.
> >
> > 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 code...so, 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?
> >
> > Thanks...
> >
> >
> > --
> > To unsubscribe, e-mail:   <mailto:tomcat-user-
> > unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <mailto:tomcat-user-
> > help@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ??? Using JSPs to Send Not-Modified-Since Header ???

Posted by Markus Kirsten <ma...@iped.vxu.se>.
Hi Tony,
Isn't it possible to put in the method after the jsp file has been 
rewritten (by Tomcat) to a standard java source code file? Maybe it's 
quick and dirty but I can't see why it shouldn't work.

Best of luck!


Markus

On Tuesday, June 4, 2002, at 09:28 AM, Tony LaPaso wrote:

> 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
> anything.
>
> 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
> container.
>
> 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 code...so, 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?
>
> Thanks...
>
>
> --
> To unsubscribe, e-mail:   <mailto:tomcat-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-
> help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>