"Anthony N. Smith-Grieco" wrote:

> What triggers the initialization servlet to start up?  Do you have a
> quickie Perl script which submits a request to that URL right after the
> site is started?
>

The details depend on which servlet engine you are using.  I have apps running
primarily on Apache JServ and on JSWDK.

JSWDK 1.0 and 1.0.1 have no built-in support for "load on startup" servlets.  What I've
done for them is a quickie program to call the URL of the startup servlet, but I wrote
it in Java (using URLConnection) instead of PERL :-).

For Apache JServ (all versions), there's a configuration setting in the zone properties
file that declares which servlets should be loaded at startup time.  Something similar
is commonly implemented in other engines.

Servlet engines that support the 2.2 API (such as Jakarta Tomcat) should *always*
support load-on-startup in a consistent manner, by virtue of the fact that you declare
your desire for such activity in the deployment descriptor.  You also get the added
ability to determine the order in which the load-on-startup servlets are initialized.

In all current scenarios, you have to be careful about what happens when your startup
servlet is unloaded.  The servlet engine reserves the right to do this at any time,
although in practice most engines only unload servlets when you shut them down, or when
you have enabled auto-reloading when the servlet class changes.  There is no
unambiguous indication of "application end" available in the servlet API.

>
> We are using Jserv (still at version 0.9-something) which allows you to
> specify a list of servlets to start immediately upon server startup.
> Also, we have a lot of servlets that use other servlets to do something,
> so the init() method for one servlet will grab a reference to another
> servlet via getServletContext().getServlet() or whatever that function is
> called. Lucky for us that Jserv automatically loads the other servlet if
> it hasn't already been loaded.. from what I've read the servlet API
> doesn't guarantee this behavior, and it's entirely possible to get a null
> return value.  What servlet engine do you use - and how does it handle
> this situation?
>

See above for handling the load-on-startup scenario.

You're going to have a serious migration issue, however, because of your use of
getServlet().  As everyone who discovers this finds out, this method has been
deprecated as of the 2.1 API, and will *always* return null.  You're going to need to
redesign your apps to be able to migrate them.  The most common scenarios (and
solutions) I've seen are as follows:

* Using other servlets as shared data containers:

    Consider storing shared data objects as servlet context attributes.

* Using shared methods from other servlets

    Consider abstracting the shared logic into separate Java classes,
    and either store instances of these classes as servlet context
    attributes, or use the Singleton design pattern with static methods.

* Using one servlet as a traffic cop to request actual output from
  a different servlet depending on current state

    Consider using RequestDispatcher.forward() or the JSP equivalent
    <jsp:forward>.

* Using the output from other servlets as input to your servlet

    Consider using RequestDispatcher.include() or the JSP equivalent
    <jsp:include> instead.

None of these redesign efforts is transparent, but you're going to have to bite this
bullet sometime, or stay on Apache JServ 0.9.x or 1.x "forever".


>
> -Tony
>

Craig McClanahan


>
>  On Sun, 28 Nov 1999, Craig R. McClanahan wrote:
>
> > For initialization, it is still something of a pain that there is no global
> > "application start" and "application stop" events in the servlet API.  I get
> > around this by using an initialization servlet like you do -- initialize the
> > resources in the init() method and finalize them in the destroy() method.  As long
> > as the servlet container does not throw out your initialization servlet (perhaps
> > because no one is calling it), this works fine.  If the server does this, you
> > might be better off moving the finalization stuff to a particular servlet that you
> > explicitly call only when you are going to shut down the server.
>
> *  Anthony Smith-Grieco   [EMAIL PROTECTED]   http://www.reed.edu/~ansmith  *
>
> ===========================================================================
> 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

===========================================================================
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

Reply via email to