Saturday, June 7, 2008

what does load-on-startup element mean in web.xml?


Question: What does the 'load-on-startup' element mean in web.xml?

Answer: This element of the Deployment Descriptor (web.xml) is used to determine the order of initializing the particular servlet when the application server starts up. The content of this element is expected to be a positive integer and lower the number, earlier the particular servlet will be initialized during server start up.

If the content is not a positive integer (or if no value is specified as the content) then the application server is free to initialize the servlet any time it wants during the server start up.

This maybe an application server dependent thing... but, I guess it's the same for almost all popular application servers currently being used like WebLogic, WebSphere, Oracle Application Server 10g, etc.

load-on-startup for Servlets:

......
<servlet id=”servlet1”>
<servlet-name>NameOfTheServlet</servlet-name>
<display-name>DisplayNameOfTheServlet</display-name>
<servlet-class>FullyQualifiedServletClassName</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
......

load-on-startup for JSPs:

......
<servlet>
<servlet-name>NameOfTheServletGenerated</servlet-name>
<jsp-file>RelativePathOfTheJSPFile</jsp-file>
<load-on-startup>3</load-on-startup>
</servlet>
......



Share/Save/Bookmark