JavaWeb --- servlet configuration in xml on the servlet init when the server starts

Why do so?
Do initialized when the server starts work [such as the] import some data into memory,
with the initialization init Servlet () method can do this.

<servlet>
	<servlet-name>myser</servlet-name>
	<servlet-class>com.wn.controller.MyServlet</servlet-class>
	<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
	<servlet-name>myser</servlet-name>
	<url-pattern>/login</url-pattern>
</servlet-mapping>

1) load-on-startup element tag servlet container if this should be loaded at boot time, (instantiate and call its init () method).

2) It must be an integer value, a sequence should be loaded servlet

3) If the element does not exist or the number is negative, the container when the Servlet is requested, re-loading.

4) When the value is 0 or greater than 0, it represents the container when the application starts to load and initialize the servlet;

5) the value of a positive number, the higher the priority of the servlet, the more loaded first when the application starts.

6) When the values ​​are the same, the container loading order of their choice.

Published 16 original articles · won praise 12 · views 4832

Guess you like

Origin blog.csdn.net/weixin_45881192/article/details/104089247