File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes What's the purpose of load-on-startup tag in web.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "What Watch "What New topic

What's the purpose of load-on-startup tag in web.xml?

Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hi Forum,

I observed following behaviour in Tomcat server.
Declare a simple Java class as a servlet using <servlet-name> and <servlet-class> tags of web.xml
and then give value given in <servlet-name> tag as a value of <load-on-startup> tag.
surprise..when server starts this class is getting Instantiated.
Here is my question..What's the purpose of <load-on-startup> tag in web.xml?
I understand that is to load servlets when webcontainer started.
Secondly will container allow a simple class that is not extending servlet class to be declared as a servlet class?
What is correct functionality according to standards?
And if I want to start some simple Java class as a startup what is standard way of doing this?
Expecting feedback.
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
The <load-on-startup> sub-element indicates the order in which each servlet has to be loaded.
Lower positive values are loaded first.
If the value is negative or unspecified, then the container can load the servlet at anytime during startup.
And about your first question, it make no sense to declare a "non servlet" class as a servlet because it is unable to accept request, so you don't need the webcontainer to map it.
[ October 04, 2002: Message edited by: Juanjo Bazan ]
I agree. Here's the link:
subject: What's the purpose of load-on-startup tag in web.xml?
It's not a secret anymore!