日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

web.xml中load-on-startup的作用

發(fā)布時(shí)間:2024/10/12 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 web.xml中load-on-startup的作用 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

今天在研究SpringMCV web.xml配置的時(shí)候發(fā)現(xiàn)load-on-startup標(biāo)簽,之前只是大概知道使用它是用來(lái)控制servlet加載順序的。今天研究了一下。

如下是從網(wǎng)上找到的一片總結(jié)的比較好的文章,和大家一起分享。

轉(zhuǎn)載自:http://www.blogjava.net/xzclog/archive/2011/09/29/359789.html

如下一段配置,熟悉DWR的再熟悉不過(guò)了:
<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.

翻譯過(guò)來(lái)的意思大致如下:
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或者沒(méi)有指定時(shí),則表示容器在該servlet被選擇時(shí)才會(huì)去加載。

4)正數(shù)的值越小,該servlet的優(yōu)先級(jí)越高,應(yīng)用啟動(dòng)時(shí)就越先加載。

5)當(dāng)值相同時(shí),容器就會(huì)自己選擇順序來(lái)加載。

所以,<load-on-startup>x</load-on-startup>,中x的取值1,2,3,4,5代表的是優(yōu)先級(jí),而非啟動(dòng)延遲時(shí)間。

如下題目:

2.web.xml中不包括哪些定義(多選)

a.默認(rèn)起始頁(yè)

b.servlet啟動(dòng)延遲時(shí)間定義

c.error處理頁(yè)面

d.jsp文件改動(dòng)后重新載入時(shí)間

答案:b,d

通常大多數(shù)Servlet是在用戶第一次請(qǐng)求的時(shí)候由應(yīng)用服務(wù)器創(chuàng)建并初始化,但<load-on-startup>n</load-on-startup>?? 可以用來(lái)改變這種狀況,根據(jù)自己需要改變加載的優(yōu)先級(jí)!

轉(zhuǎn)載于:https://www.cnblogs.com/0xcafedaddy/p/5364500.html

總結(jié)

以上是生活随笔為你收集整理的web.xml中load-on-startup的作用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。