See below.

Floyd Marinescu wrote:

> For websites that typically display information that doesn't change often
> (ie: a bookstore, etc), it doesn't make sense to regenerate catalogue type
> pages on every web request.
>
>     For architectures using the Model 2 servlet jsp interaction (servlet
> pre-populates a bean and sends it off to a jsp), a simple web server side
> html cache can be implemented if the servlet can capture the output of the
> jsp and save it to a file, and later just serve that file until you decide
> to regenerate the page again.
>
>     I have tried to implement this, but I can't come up with the simple code
> to capture jsp output from within the servlet.
>
>    The problem essentially boils down to this:
>
>   Whereas before I had the following line of code:
> //send beans from servlet to jsp and client
> getRequestDispatcher("someJSP.jsp").forward(req, resp);
>
>  I need to replace it with some code that will not forward the
> request and response but instead capture the output of the jsp.
> The closest thing I have found is:
>
> getRequestDispatcher("someJSP.jsp").include(req, resp);
>
>  But this adds the content to the response object, and I don't
>  know how to take that content out of the response and save it to a file..
>
>    Does anyone have any ideas?
>
> thanks,
>
> Floyd Marinescu
>

IDEA #1:

I have not tried this, but a different approach should be feasible, based on the
fact that the generated code for a JSP page is actually a servlet.  In the
javax.servlet.http.HttpServlet class, there is a method called
getLastModified(), which is called when the browser issues a conditional GET
request.  If the server determines that the last modified time is before that
specified by the brower, it will send a "Not Modified" response back, instead of
the page contents.

So, the idea would be to define a getLastModified() method in your JSP page
(inside <%! %>) that could be used to determine whether this particular page has
been modified or not.  Users who have never visited that page, or who have it in
their cache but older than the most recent modification timestamp, will
automatically receive the page and cache it.  Users who already have the current
copy of the page cached will simply redisplay it, and your JSP page service()
method won't get called again.


IDEA #2:

If the content of these pages is actually static, why use JSP at all?  Why not
just generate HTML pages through some external means, and serve them directly?
(This would have the effective benefit of the get last modified approach,
because web servers do that for you based on the modification date/time of the
HTML files).


COMMON QUESTION:

Under either approach, is the static catalog page content *really* static?  I've
seen catalog sites that have common portions, but the overall display depends on
things like how I got there (if you display a breadcrumb trail), or the choices
being presented are selected and/or sorted based on things in the user's
personal profile, which would require dynamic pages that really are different
every time you call them.

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to