"Turn" the role of Load-on-startup in Web. xml

Source: Internet
Author: User

Http://www.blogjava.net/xzclog/archive/2011/09/29/359789.html

The following configuration, familiar with DWR is familiar:
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

We notice that it contains this configuration: <load-on-startup>1</load-on-startup> So what does this configuration do?

An explanation of the original English is as follows:
Servlet Specification:
The Load-on-startup element indicates, this servlet should is loaded (instantiated and has its init () called) on the Startup of the Web application. The optional contents of these element must be a integer indicating the order in which the servlet should is loaded. If The value is a negative integer, or the element was not present, and the container is free to load the servlet whenever it C   Hooses. 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 is loaded before servlets marked with higher intege Rs. The container may choose the order of loading of servlets with the same load-on-start-up value.

The meaning of the translation comes roughly as follows:
1) The Load-on-startup element flags whether the container loads the servlet at startup (instantiating and invoking its init () method).

2) Its value must be an integer indicating the order in which the servlet should be loaded

2) A value of 0 or greater than 0 o'clock indicates that the container loads and initializes the servlet when the application is started;

3) When the value is less than 0 or unspecified, the container will not load until the servlet is selected.

4) The lower the value of a positive number, the higher the precedence of the servlet, and the more loaded it will be when the app starts.

5) At the same time, the container will be loaded in its own order of choice.

So, <load-on-startup>x</load-on-startup>, the value 1,2,3,4,5 in X represents the priority, not the start delay time.

Why is it not true and false? This is because if we set up multiple Servlets in Web. XML, we can use Load-on-startup to specify the order in which the servlet is loaded, and the server initializes the servlet according to the size of the load-on-startup. But even if we set the Load-on-startup to repeat, there will be no exceptions, and the server will decide the order of initialization itself.

The following topics:

What definitions are not included in 2.web.xml (multiple selection)

A. Default Start Page

B.servlet Start delay Time definition

C.error Processing page

Reload time after d.jsp file changes

Answer: B,d

Most servlets are usually created and initialized by the application server when the user first requests it, but <load-on-startup>n</load-on-startup> can be used to change the situation. Change the priority of loading according to your needs!

"Turn" the role of Load-on-startup in Web. xml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.