473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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>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
Jul 17 '05 #1
2 11908
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" <rf******@hotmail.com> wrote in message
news:96**************************@posting.google.c 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

Jul 17 '05 #2
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
jo******@indiana.edu

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: K S Aldebaraan | last post by:
I'm trying to submit a form with an action of a servlet, and a view equal to the same jsp page. I'm not sure what I'm doing wrong, but keep getting a NullPointerException on the second line of...
3
by: TheLetti | last post by:
Hy! I've just downloaded the latest Java 2 SDK (j2sdk1.4.2_01). For my surprise in this version the servlet-classes are not integrated (e.g. the class javax.servlet). So I found all the...
1
by: Hai Tran | last post by:
Any help is appreciated. Installed Tomcat 4.1 and Mysql on a WinXP. I've manage to get Tomcat up and was able to view my first application ( myhome ) simple home page. Tomcat was installed under...
2
by: Dave Calkins | last post by:
I'm wriiting an MFC C++ application which uses a third party C# .NET API via a DLL. The app runs fine. If I add a new, empty C++ class, and compile/link it refuses to run, complaining about not...
0
by: =?Utf-8?B?R2FyeSBNY0M=?= | last post by:
The quick launch tool bar doesn't load on startup in my user account. It works fine by clicking on the Task bar and selecting Quick Launch, but it doesn't seem to save the setting when I shut down...
9
by: SAL | last post by:
I have an ASP.NET 2.0 app that takes about 17 seconds to load on first startup but then is very fast after that. As I understand it from some posts in June, this is caused by the loading of the App...
3
by: krishna81m | last post by:
Hello, I am looking for a solution to update a .jsp page (kind of progress bar) which shows current progress in a huge simulation when users have to wait for longer periods and the way to do it...
1
by: sureshyerva | last post by:
i need a servlet to be loaded by the server on startup in my application. How it can be done.plz help me out...........
9
by: mjahabarsadiq | last post by:
Hi I have created a servlet that is to be started at the server startup. And I got it. In that I have created a object of another class and set it as a session attribute. What I am trying is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.