Friday, 22 April 2016

What is the use of load-on-startup tag ?


If you have multiple servlets that you want preloaded, and you want to control the order in which they’re initialized, use tag <load-on-startup>

Example
<servlet>
    <servlet-name>TestServlet1</servlet-name>
    <servlet-class>com.test.TestServlet1</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>TestServlet2</servlet-name>
    <servlet-class>com.test.TestServlet2</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

It indicates that the servlet should be loaded (instantiated and init() is called) on the startup of the web application. 

Here, TestServlet1 will be loaded first, then TestServlet2.

What will happen will we declare a negative value (< 0) , servlet will not be loaded on startup and container will decide when to load the servlet.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.