my servlet won't load on startup in tomcat4, any ideas why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robert walker

    my servlet won't load on startup in tomcat4, any ideas why?

    hi all,

    to my webapp named mrf, i have added load-on-startup tag
    to mrf\WEB-INF\web.xml

    so i added a snippet like so

    <servlet>
    <servlet-name>loadDbProp erties</servlet-name>
    <servlet-class>mrf.LoadD bPropertiesServ let</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    this servlet just initalizes a connecion pool
    *************** *************** ***
    public class LoadDbPropertie sServlet extends HttpServlet {

    public static Properties dbProperties;

    public void init() throws ServletExceptio n
    {
    ConnectionPool connPool =
    (ConnectionPool )getServletCont ext().
    getAttribute("C ONNECTION_POOL" );

    if (connPool==null )
    {
    ServletContext sc =
    getServletConfi g().getServletC ontext();
    try {
    dbProperties.lo ad(sc.getResour ceAsStream("/WEB-INF/properties/db.properties") );

    connPool =
    new ConnectionPool( (String)dbPrope rties.get("dbdr iver"),
    (String)dbPrope rties.get("dbur l"),
    (String)dbPrope rties.get("user "),
    (String)dbPrope rties.get"passw ord"),
    Integer.parseIn t((String)dbPro perties.get("in itconns")),
    Integer.parseIn t((String)dbPro perties.get("ma xconns")),
    true);

    getServletConte xt().setAttribu te("CONNECTION_ POOL",connPool) ;

    }catch(Exceptio n ioe){ioe.printS tackTrace();}
    }
    }
    }
    *************** *************** *************

    (also tried to put it in tomcat\conf\web .xml but still it does not
    load on startup)


    why the heck does this not load on startup? i looked for messages on
    the groups but still unsure what i am doing wrong

    thaks for any insight
  • Andy Flowers

    #2
    Re: my servlet won't load on startup in tomcat4, any ideas why?

    Which version of Tomcat ?

    Also check if the servlet is throwing any exceptions and being shutdown ?

    You should look in the all the logs to see if there's anything useful in
    there.

    "robert walker" <rfwalker@hotma il.com> wrote in message
    news:96b82441.0 307311211.37153 eaf@posting.goo gle.com...[color=blue]
    > hi all,
    >
    > to my webapp named mrf, i have added load-on-startup tag
    > to mrf\WEB-INF\web.xml
    >
    > so i added a snippet like so
    >
    > <servlet>
    > <servlet-name>loadDbProp erties</servlet-name>
    > <servlet-class>mrf.LoadD bPropertiesServ let</servlet-class>
    > <load-on-startup>1</load-on-startup>
    > </servlet>
    >
    > this servlet just initalizes a connecion pool
    > *************** *************** ***
    > public class LoadDbPropertie sServlet extends HttpServlet {
    >
    > public static Properties dbProperties;
    >
    > public void init() throws ServletExceptio n
    > {
    > ConnectionPool connPool =
    > (ConnectionPool )getServletCont ext().
    > getAttribute("C ONNECTION_POOL" );
    >
    > if (connPool==null )
    > {
    > ServletContext sc =
    > getServletConfi g().getServletC ontext();
    > try {
    >[/color]
    dbProperties.lo ad(sc.getResour ceAsStream("/WEB-INF/properties/db.properties"
    ));[color=blue]
    >
    > connPool =
    > new ConnectionPool( (String)dbPrope rties.get("dbdr iver"),
    > (String)dbPrope rties.get("dbur l"),
    > (String)dbPrope rties.get("user "),
    > (String)dbPrope rties.get"passw ord"),
    > Integer.parseIn t((String)dbPro perties.get("in itconns")),
    > Integer.parseIn t((String)dbPro perties.get("ma xconns")),
    > true);
    >
    >[/color]
    getServletConte xt().setAttribu te("CONNECTION_ POOL",connPool) ;[color=blue]
    >
    > }catch(Exceptio n ioe){ioe.printS tackTrace();}
    > }
    > }
    > }
    > *************** *************** *************
    >
    > (also tried to put it in tomcat\conf\web .xml but still it does not
    > load on startup)
    >
    >
    > why the heck does this not load on startup? i looked for messages on
    > the groups but still unsure what i am doing wrong
    >
    > thaks for any insight[/color]


    Comment

    • John C. Bollinger

      #3
      Re: my servlet won't load on startup in tomcat4, any ideas why?

      robert walker wrote:[color=blue]
      > thanks for the suggestions,
      > the logs look error free, its tomcat v4.0
      >
      > i changed it to a listener and it now works like I expected
      > the load-on-startup to work.[/color]

      <stand on="soapbox">
      A ServletContextL istener is the correct way to do the kind of thing you
      want. Using load-on-startup servlets for the purpose is an
      unfortunately common hack whose popularity, I assume, arises from the
      fact that it leverages servlet developers' existing skills better. If a
      piece of code is not intended to process ServletRequests then it should
      not be written as a Servlet. Period.
      </stand>

      With that said, your servlet container is broken if it does not load a
      servlet with specified non-negative load-on-startup as part of a
      successful application startup. In this context, to "load" the servlet
      means to load its class, create an instance, and invoke the instance's
      init() method. The servlet container is not required to retain the
      instance for any particular amount of time, however. Also, the relative
      order in which load-on-startup servlets with the same priority number
      are loaded is dontainer-dependant.

      Since Tomcat is good and quite stable, I'd have to guess that something
      was wrong with your webapp when you were trying to use load-on-startup.
      There are many possibilities, including

      () Wrong version of the servlet class was used. This can happen if you
      fail to update WEB-INF/classes or WEB-INF/lib, whichever you are using.
      A particularly nasty case can occur if you duplicate your classes in
      both places (not recommended) and only update one: you think you've
      updated it, but the behavior doesn't change.

      () Wrong web.xml was updated, or web.xml was in the wrong place, or
      working copy of web.xml was not deployed

      () Modifications to web.xml were applied inside XML comments

      () The wrong servlet was set to load on startup


      John Bollinger
      jobollin@indian a.edu

      Comment

      Working...