*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "What Watch "What New topic
Author

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

Manohar Karamballi
Ranch Hand

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

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.
Cheers
Manohar
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: http://aspose.com/file-tools
 
subject: What's the purpose of load-on-startup tag in web.xml?
 
Similar Threads
Servlet doesn't pick initial parameter
How to configure Tomcat to load a servlet
How to execute a function when struts loads?
load on startup
Deploying Struts app on Linux server