Servlet specification中关于load-on-startup的解释:
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.
load-on-startup选项在web.xml中有以下几个注意点:
1. load-on-startup表明在应用程序启动的时候执行指定的servlet,load-on-startup中的数字越低表明启动越早。比较有用的是Struts中的org.apache.struts.action.ActionServlet,例如:
action
org.apache.struts.action.ActionServlet
config
/WEB-INF/struts-config.xml
debug
2
application
ApplicationResources
2
还有像使用proxool配置连接池等,都需要在启动时启动。
2. load-on-startup指定的servlet在执行后,应用程序才正式启动。否则,在servlet未成功处理前,无法访问应用程序。
本文介绍了Servlet specification中load-on-startup的含义,即指定Servlet在Web应用启动时加载。其值为整数,负数时容器自行选择加载时间,正数或0则在应用部署时加载,数字越小越先加载。还提及在web.xml中使用该选项的注意点,如Struts的ActionServlet需在启动时加载。
1001

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



