• September 14, 2014
  • Servlet
  • Comments Off on load-on-startup in web.xml

load-on-startup in web.xml

load-on-startup:

The load-on-startup is the sub attribute of servlet attribute in web.xml. It is used to control when the web server loads the servlet. As we discussed that servlet is loaded at the time of first request. In this case response time is increased for first request. If load-on-startup is specified for a servlet in web.xml then this servlet will be loaded when the server starts. So the response time will not increase for fist request.

Any positive or negative value can be passed in the load-on-startup. If positive value is passed then all servlets having load-on-startup sub attribute will be loaded when server starts but a servlet having low positive value will be loaded first. In case of negative value servlet will be loaded at the time of first request.

Sample code of load-on-startup in web.xml.

<web-app>
 
   //other attributes  
 
   <servlet>  
 	<servlet-name>servlet1</servlet-name>  
  	<servlet-class>com.javawithease.business.Servlet1 </servlet-class>
   	<load-on-startup>0</load-on-startup>  
   </servlet>  
 
  <servlet>  
  	 <servlet-name>servlet2</servlet-name>  
   	<servlet-class> com.javawithease.business.Servlet2</servlet-class>
   	<load-on-startup>1</load-on-startup>  
  </servlet>    
 
  <servlet>  
  	<servlet-name>servlet3</servlet-name>  
   	<servlet-class> com.javawithease.business.Servlet3</servlet-class>
   	<load-on-startup>-1</load-on-startup>  
  </servlet>  
 
  //other attributes
 
</web-app>

In the above example Servlet1 and Servlet2 will be loaded when server starts because positive value is passed in there load-on-startup. Servlet3 will be loaded at the time of first request because negative value is passed in there load-on-startup.
 
Next Topic: RequestDispacher interface with example.
Previous Topic: welcome-file-list in web.xml with example.

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.

 


Comments are closed.