Why are we writing <load-on-startup> 2 </load-on-startup> in web.xml when using struts 1.x?

I am very new to J2EE, considering the same, please answer. When we use struts, why do we write < load-on-startup>2</load-on-startup> in the servlet tag? What does this tag mean? If something loads seconds, then what are the loads first? Also provide some links that explain to me all the structs-config.xml tags

+8
java java-ee servlets
source share
5 answers

load-on-startup tells the servlet container to load the specified resource when the server starts. The quantity you see indicates the startup order if more than one load-on-startup tag exists.

 <load-on-startup>1</load-on-startup> <load-on-startup>2</load-on-startup> 

will lead to loading the resource with loading at startup 1. This is to control the sequence of loading, if there is a dependency. Take a look at the servlet spec that explains the loading sequence.

The answer I mentioned in my comment below (Ref http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ):

  <xsd:element name="load-on-startup" type="javaee:load-on-startupType" minOccurs="0"> <xsd:annotation> <xsd:documentation> 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 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. </xsd:documentation> </xsd:annotation> </xsd:element> 

Read the documentation carefully.

+10
source share

See http://struts.apache.org/1.x/userGuide/configuration.html .

load-on-startup means that the servlet must be loaded and initialized when the webapp starts (that is, as soon as it is deployed, without waiting for the request for the servlet). The number indicates the initialization order. If the other servlet has 1, it will be loaded earlier. If the other has 3, it will be loaded after.

+8
source share

If you use Tomcat, there are several servlets that are loaded for each web application:

  • default servlet (usually used for static content and responds to any unreferenced URL)
  • jsp servlet

Looking at the default Tomcat web.xml configuration file ...

 <servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> ... <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> ... <load-on-startup>3</load-on-startup> </servlet> 

Note that the default value is 1, and jsp is 3.

Thus, using <load-on-startup>2</load-on-startup> means that your servlet will be loaded during deployment after the default servlet, but before the jsp servlet.

+3
source share

load-on-startup tells the container to load the servlet during application startup. The assigned number is the servlet rank that reports the load order of the load servlet.

+2
source share

1) is the element that is used in "web.xml".

2) This element indicates the web container for loading the server specified by this element.

3) The order is based on the quantity indicated inside the tag Example: 1 2 1-server executed first, then it moves to 2 ..,

0
source share

All Articles