如下一段配置,熟悉DWR的再熟悉不過了:<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>
我們注意到它里面包含了這段配置:<load-on-startup>1</load-on-startup>,那么這個(gè)配置有什么作用呢?
貼一段英文原汁原味的解釋如下:
Servlet specification:
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.
翻譯過來的意思大致如下:
1)load-on-startup元素標(biāo)記容器是否在啟動(dòng)的時(shí)候就加載這個(gè)servlet(實(shí)例化并調(diào)用其init()方法)。
2)它的值必須是一個(gè)整數(shù),表示servlet應(yīng)該被載入的順序
2)當(dāng)值為0或者大于0時(shí),表示容器在應(yīng)用啟動(dòng)時(shí)就加載并初始化這個(gè)servlet;
3)當(dāng)值小于0或者沒有指定時(shí),則表示容器在該servlet被選擇時(shí)才會(huì)去加載。
4)正數(shù)的值越小,該servlet的優(yōu)先級越高,應(yīng)用啟動(dòng)時(shí)就越先加載。
5)當(dāng)值相同時(shí),容器就會(huì)自己選擇順序來加載。
所以,<load-on-startup>x</load-on-startup>,中x的取值1,2,3,4,5代表的是優(yōu)先級,而非啟動(dòng)延遲時(shí)間。
如下題目:
2.web.xml中不包括哪些定義(多選)
a.默認(rèn)起始頁
b.servlet啟動(dòng)延遲時(shí)間定義
c.error處理頁面
d.jsp文件改動(dòng)后重新載入時(shí)間
答案:b,d
通常大多數(shù)Servlet是在用戶第一次請求的時(shí)候由應(yīng)用服務(wù)器創(chuàng)建并初始化,但<load-on-startup>n</load-on-startup> 可以用來改變這種狀況,根據(jù)自己需要改變加載的優(yōu)先級!
posted on 2011-09-29 15:22
xzc 閱讀(149944)
評論(22) 編輯 收藏 所屬分類:
Web 、
Java