Michael Hu wrote:
> There are three places where a JSP page author can allocate limited resources:
>
> 1) _jspInit() which is cleaned up by _jspDestroy(), both of which are guaranteed to
>be
> called at the appropriate times in 1.1 spec.
Once -- during engine/application start and stop -- not on a per-request basis.
> 2) <% scriptlets %> It is the responsibility of the JSP author to wrap resource
> allocations in try/catch/finally blocks
Clearly -- though it is a secret goal of mine to avoid non-client code in my HTML
templates :)
> 3) Custom tags. Tag.release() must be called in a finally block by a JSP 1.1
>compliant
> implementation of a custom tag.
Tag.release implies that the end tag surrounds the entire use of the resources
that the Tag defines. I don't think that that is a reasonable assumption, and
there's already a really good example why -- useBean.
Aside from design paradigms, there are other reasons why one would not want
to surround the entire page in a tag. Streaming allows some of the page to be
shown to the user as the server constructs it. Unfortunately, Tags interrupt
streaming (the body is buffered).
> Implicitly, the JSP engine will allocate resources in the pageContext. Although not
> explictly demanded by the specs, it should be safe to assume that
>releasePageContext()
> will be called in service's finally block for JSP 1.1 compliant implementations
>(refer
> to page 112 and 139 of the JSP 1.1 specs).
Err, the javadoc I read noted a releasePageContext() call in the JspFactory, not
one on the JSPServlet. Did I miss this? releasePageContext() did seem a
natural place to release transient, system resources, though not ideally named....
> > Which brings up another interesting point -- are the doEndTag()
> > calls intended to be called even in the case of forward()? I can
> > imagine some looping tags would hold onto system-type resources as well.
> No, it is the responsiblity of the tag author to free up resources before
><jsp:forward>
> (ie: "a goto and never return") is called. <jsp:forward> means that the rest of the
> page will never be called, including releasePageContext. Like in C, use goto's with
> caution!
Sure, I agree. The problem isn't with <jsp:forward>, which is an explicit goto.
The problem is with arbitrary, 3rd-party tags which perform forwards. Possibly
conditionally. Which makes resource deallocation somewhat non-trivial, yes?
-Dave
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html