wood burning stoves*
The moose likes Struts and the fly likes what does <load-on-startup> do 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 » Frameworks » Struts
Bookmark "what does <load-on-startup> do in web.xml ?" Watch "what does <load-on-startup> do in web.xml ?" New topic
Author

what does <load-on-startup> do in web.xml ?

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
what does <load-on-startup> in the below code do ?



Following are my queries:-
Ques1 What does 1 signifies ?
Ques2 Does it load ActionServlet(org.apache.struts.action.ActionServlet) or does it load Struts-Config.xml file ?
Ques3 What if i write something like this

Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Servlets are not loaded until they are first accessed by a request. This may result in a slow access time for the first user. The load-on-startup tag allows you to force the container to load and initialize the servlet at startup.

1. The "1" is used to give a startup order when other servlet are also using load-on-startup. From the servet specification:

The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive 128 integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.


2. It initializes ActionServlet, which reads your configuration file

3. Try it But now you should already have an idea of what's going to happen.


[My Blog]
All roads lead to JavaRanch
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
Christophe Verré wrote:Servlets are not loaded until they are first accessed by a request. This may result in a slow access time for the first user. The load-on-startup tag allows you to force the container to load and initialize the servlet at startup.

1. The "1" is used to give a startup order when other servlet are also using load-on-startup. From the servet specification:

The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive 128 integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.


2. It initializes ActionServlet, which reads your configuration file

3. Try it But now you should already have an idea of what's going to happen.




Chris, my next question, now what happens if
i put a negative integer say -1
or, i put zero o
or i just remove the this tag completely ???

Thanks in advance
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Read again:
If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses.
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
Christophe Verré wrote:Read again:
If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses.


Thanks, i just skipped that, my mistake.

ok, let me summarizes it once again,
for 0 or greater than 0, the container will load the servlet when the server gets started and when the element tag is not present or for negative integers, the container will only load the servlet when the 1st request comes to it and not during server startup., am i right ???
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes. To be more precise, if it is negative or more present, the container is free to load it whenever it wants. Might be at startup. Might be at the first request. If you want to ensure that it is loaded at startup, you'll have to use <load-on-startup> with a value >= 0.
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
Christophe Verré wrote:Yes. To be more precise, if it is negative or more present, the container is free to load it whenever it wants. Might be at startup. Might be at the first request. If you want to ensure that it is loaded at startup, you'll have to use <load-on-startup> with a value >= 0.


thanks alot.....appreciated
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what does <load-on-startup> do in web.xml ?
 
Similar Threads
struts.xml file
Struts.xml file in Eclipse
java.lang.NullPointerException at the starting of tomcat 6.0
The method doMarkDoneOutboundCall(null, String) is undefined for the type Done_jsp
Need related struts subapps in one struts app