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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With