Explain in detail the role of servlet configuration load on startup

In servlet configuration, < load on startup > 1 < / load on startup > means to mark whether the container loads the servlet at startup.

When the value is 0 or greater than 0, it means that the container loads the servlet when the application starts; When it is a negative number or is not specified, it indicates that the container will not load until the servlet is selected.

The lower the value of a positive number, the higher the priority of starting the servlet.

If we're on the web When multiple servlets are set in XML, you can use load on startup to specify the loading order of servlets, and the server will initialize the servlets in turn according to the size of load on startup. However, even if we repeat the load on startup setting, there will be no exception. The server will decide the initialization order by itself.

After configuring load on startup, the servlet loads immediately after startup, but only calls the init () method of the servlet to initialize the resources related to the servlet. After successful initialization, the servlet can respond to web requests; If load on startup is not configured, the container will first check whether the servlet is initialized when responding to the web request for the first time. If not, it will call init() of the servlet to initialize first, and then respond to the request after successful initialization.

PS: generally, we will configure this parameter when developing web applications. It has two advantages: 1. If the initialization process fails, the container will prompt for startup failure. At this time, we can know the relevant errors in advance; 2. Configuring this parameter is equivalent to transferring the work of initializing the servlet to the container startup process, so that the container can respond to web requests as soon as it is successfully started.

Example: determine whether to connect to the network

1、web. xml

2、Servlet

3、index. html

That's all for the detailed explanation of the role of servlet configuration load on startup in this article. I hope it will be helpful to you. Interested friends can refer to: Java, JSP, servlet to obtain the current project path (absolute path) problem analysis and other related topics. Thank you for your support for this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>