Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why we write <load-on-startup>2</load-on-startup> in web.xml while using struts 1.x? [duplicate]

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

like image 344
amod Avatar asked Oct 18 '11 06:10

amod


2 Answers

load-on-startup tells the servlet container to load the specified resource at server startup. The number that you see tells the order of startup if there are more than one load-on-startup tag.

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

will cause the resource with load on startup 1 to be loaded first. This is to control the sequence of loading if there is a dependency. Look at the servlet specification that explains the load sequence.

The answer I referred to 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.

like image 62
Ayusman Avatar answered Sep 21 '22 16:09

Ayusman


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

load-on-startup means that the servlet must be loaded and initialized on startup of the webapp (i.e. as soon as it is deployed, without waiting for a request to the servlet). The number indicates the order of the initialisations. If another servlet has 1, it will be loaded before. If another has 3, it will be loaded after.

like image 22
JB Nizet Avatar answered Sep 19 '22 16:09

JB Nizet