Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > my servlet won't load on startup in tomcat4, any ideas why?

Reply
Thread Tools

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

 
 
robert walker
Guest
Posts: n/a
 
      07-31-2003
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>loadDbProperties</servlet-name>
<servlet-class>mrf.LoadDbPropertiesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

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

public static Properties dbProperties;

public void init() throws ServletException
{
ConnectionPool connPool =
(ConnectionPool)getServletContext().
getAttribute("CONNECTION_POOL");

if (connPool==null)
{
ServletContext sc =
getServletConfig().getServletContext();
try {
dbProperties.load(sc.getResourceAsStream("/WEB-INF/properties/db.properties"));

connPool =
new ConnectionPool((String)dbProperties.get("dbdriver" ),
(String)dbProperties.get("dburl"),
(String)dbProperties.get("user"),
(String)dbProperties.get"password"),
Integer.parseInt((String)dbProperties.get("initcon ns")),
Integer.parseInt((String)dbProperties.get("maxconn s")),
true);

getServletContext().setAttribute("CONNECTION_POOL" ,connPool);

}catch(Exception ioe){ioe.printStackTrace();}
}
}
}
*******************************************

(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
 
Reply With Quote
 
 
 
 
Andy Flowers
Guest
Posts: n/a
 
      07-31-2003
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" <> wrote in message
news: om...
> 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>loadDbProperties</servlet-name>
> <servlet-class>mrf.LoadDbPropertiesServlet</servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
> this servlet just initalizes a connecion pool
> *********************************
> public class LoadDbPropertiesServlet extends HttpServlet {
>
> public static Properties dbProperties;
>
> public void init() throws ServletException
> {
> ConnectionPool connPool =
> (ConnectionPool)getServletContext().
> getAttribute("CONNECTION_POOL");
>
> if (connPool==null)
> {
> ServletContext sc =
> getServletConfig().getServletContext();
> try {
>

dbProperties.load(sc.getResourceAsStream("/WEB-INF/properties/db.properties"
));
>
> connPool =
> new ConnectionPool((String)dbProperties.get("dbdriver" ),
> (String)dbProperties.get("dburl"),
> (String)dbProperties.get("user"),
> (String)dbProperties.get"password"),
> Integer.parseInt((String)dbProperties.get("initcon ns")),
> Integer.parseInt((String)dbProperties.get("maxconn s")),
> true);
>
>

getServletContext().setAttribute("CONNECTION_POOL" ,connPool);
>
> }catch(Exception ioe){ioe.printStackTrace();}
> }
> }
> }
> *******************************************
>
> (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



 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      08-04-2003
robert walker wrote:
> 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.


<stand on="soapbox">
A ServletContextListener 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any online information of Vignette-based servlet to Websphere-based servlet? Phil Powell Java 0 08-29-2007 01:29 PM
PC won't load any services on startup - stuck in diagnostic mode? Panserbjorn Computer Support 4 02-14-2007 02:28 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
RubyGems Load Error Problem -- Any Ideas? Anthony Baker (ThinkBigIdeas) Ruby 3 02-09-2005 08:42 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57