Application lifecycle events, such as those defined in ASP's global.asa
file, should be implemented (although not identically) in the Servlet2.3 /
JSP1.2 API. See:
http://developer.java.sun.com/developer/technicalArticles/Servlets/servletap
i2.3/
This should be released very soon, and be in Tomcat 4.0 as I understand it.
However, I have another suggestion that can solve this problem *now* (works
with Tomcat and Resin, for example). In the web server configuration files
(normally web.xml, but may vary), in around the same place as you define
servlet mappings, you can normally add a "load-on-startup" parameter. Make
a servlet which does all application initialisation tasks in its init()
method, and all shutdown tasks in its destroy() methods. It's not necessary
to provide a doGet() or doPost() method (as such, better with a servlet than
a JSP). This does work, I've tried it.
As for session tracking using current APIs... test whether a session exists
at the start of the request handling method (typically the doGet() method of
your homepage servlet). If not, create an instance of an object that
implements the HttpSessionBindingListener interface in javax.servlet.http,
and put it into the session, using HttpSession.setAttribute(). This is an
object can handle being added to the session and removed from the session,
and should therefore receive an event when the session ends (normally or
after a timeout). This object can effectively work like ASP's Global.asa's
Session_OnStart and _OnEnd functions. This should be just as easy to do
with JSPs as with Servlets. I haven't tried this out yet with servlets or
JSP, but I see no reason why it shouldn't work.
I would prefer my suggested approaches rather than implementation-specific
extensions to the Servlet API, especially, as I suspect they may at some
point be abandonned in favour of the newer standardised approaches.
-Chris
----- Original Message -----
From: "Rob L'Estrange" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 17, 2001 10:56 PM
Subject: Global.jsa ?
> Hi All
>
> Does the JSP framework make use of a Global.jsa file, similar to how the
the
> ASP framework makes use of a Global.asa file? If not, is there something
in
> the JSP framework that plays this role? In particular, I'm interested in
> application and/or session start/end events, and the ability to centrally
> declare variables with application and/or session scope.
>
> Thanks
> Rob
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> 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
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
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