Aaron Tavistock wrote:
>
> I'm working on a project that is driven by taglibs, basically everything
> that needs to be done will be done with taglib (e.g. no java or JSP
> actions on the page except the preamble).
>
> Since taglibs always get put into _jspService as new classes, all the
> objects are generated on a per-request basis.  I'm also using the
> servletContext to retain references to objects that need to be kept
> across several applications (e.g. database pools, etc).  Overall this
> works just fine for many things.
>
> Unfortunately I'm getting to a stage where I'd like to optimize the
> application by moving the static/semi-static per-request data out into
> the persistent space in the servlet.  In normal JSP I would do this
> using declarations (<%! ... %>), but from a taglib it appears imposible.
>
> I'm not entirely sure that this is the place to make a suggestion for
> the next taglib spec release, but it would be useful to provide support
> for declarations and/or lifecycle management from within a taglib.
>
> Just a thought.

I suggest you use the appropriate JSP scopes to save your static/semi-static
data. A tag handler has access to all scopes through the pageContext object.
So if you need to let one custom action create data used by another on the
same page, save it in the page scope. If it's needed by a custom action on
another page handling the same request, use the request scope, and so forth.

I always warn about using <!% ... %> due to the multithreading issues than
many are not aware of. But if you need something that mimics what an instance
variable for a specific page gives you, you can save data in a keyed collection
(e.g. a Hashtable) where the JSP page name is used as the key. In your tag
handlers you must be careful to synchronize access to this data though.

Life-cycle management for tag libraries is also one of the areas to be
looked at for the next version of the JSP spec.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to