load-on-startup 元素在web应用启动的时候指定了servlet被加载的顺序,它的值必须是一个整数。如果它的值是一个负整数或是这个元素不存在,那么容器会在该 servlet被调用的时候,加载这个servlet 。如果值是正整数或零,容器在配置的时候就加载并初始化这个servlet,容器必须保证值小的先被加载。如果值相等,容器可以自动选择先加载谁。
(补充:servlet的init() 方法
在Servlet的生命周期中,仅执行一次 init() 方法,即在服务器装入Servlet时执行。通过配置服务器,可以设定在启动服务器或客户机首 次访问Servlet 时装入Servlet。无论有多少客户机访问Servlet,都不会重复执行 init()。 )
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.
本文详细解释了在Web应用启动过程中,servlet是如何被加载及初始化的。通过load-on-startup元素,开发者可以指定servlet的加载顺序。若值为正整数或0,则容器在部署时加载servlet;若值为负数或未设置,则容器可在任意时刻加载。servlet的init()方法仅在servlet首次被加载时执行。
211

被折叠的 条评论
为什么被折叠?



