1. 程式人生 > >web.xml中load-on-startup的作用

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

如下一段配置,熟悉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>,那麼這個配置有什麼作用呢?

貼一段英文原汁原味的解釋如下:


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元素標記容器是否在啟動的時候就載入這個servlet(例項化並呼叫其init()方法)。

2)它的值必須是一個整數,表示servlet應該被載入的順序

2)當值為0或者大於0時,表示容器在應用啟動時就載入並初始化這個servlet;

3)當值小於0或者沒有指定時,則表示容器在該servlet被選擇時才會去載入。

4)正數的值越小,該servlet的優先順序越高,應用啟動時就越先載入。

5)當值相同時,容器就會自己選擇順序來載入。

所以,<load-on-startup>x</load-on-startup>,中x的取值1,2,3,4,5代表的是優先順序,而非啟動延遲時間。

如下題目:

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

a.預設起始頁

b.servlet啟動延遲時間定義

c.error處理頁面

d.jsp檔案改動後重新載入時間

答案:b,d

通常大多數Servlet是在使用者第一次請求的時候由應用伺服器建立並初始化,但<load-on-startup>n</load-on-startup>   可以用來改變這種狀況,根據自己需要改變載入的優先順序!

相關推薦

web.xmlload-on-startup作用

如下一段配置,熟悉DWR的再熟悉不過了:<servlet>   <servlet-name>dwr-invoker</servlet-name>   <servlet-class>org.directwebremoting.s

web.xmlload-on-startup作用(新解)

1、load-on-startup元素標記容器是否在啟動的時候就載入這個servlet(例項化並呼叫其init()方法)。 2、它的值必須是一個整數,表示servlet應該被載入的順序 3、當值為0或者大於0時,表示容器在應用啟動時就載入並初始化這個servlet; 4、當值小於0或者沒有指定時,則

【轉載】web.xmlload-on-startup作用

轉載地址:http://www.blogjava.net/xzclog/archive/2011/09/29/359789.html 如下一段配置,熟悉DWR的再熟悉不過了: < servlet > < servlet-name&g

web.xmlload-on-startup的含義

在servlet的配置當中,<load-on-startup>5</load-on-startup>的含義是: 標記容器是否在啟動的時候就載入這個servlet。 當值為0或者大於0時,表示容器在應用啟動時就載入這個servlet; 當是一個負數時或者

servlet開發web.xmlload-on-start標籤作用

web.xml中<load-on-start>n</load-on-satrt>作用   如下面一段配置,我們再熟悉不過了:      我們注意到它裡面包含了這段配置:<load-on-startup>1</load-on-startup&g

web.xml,標籤的作用

1.啟動一個WEB專案的時候,容器(如:Tomcat)會去讀它的配置檔案web.xml.讀兩個節點: <listener></listener> 和 <context-param></context-param> 2.緊接著,容器建立一個ServletCont

web.xml的contextConfigLocation的作用

如果在web.xml裡給該Listener指定要載入的xml,如: xml程式碼如下: <!-- spring config -->       <context-param>            <param-name>contextConfigLocation<

---Filter ( 三 ) web.xmldispatcher節點的作用

Filter的作用 Filter的目的就是在請求和響應之間攔截檢查請求相應的內容。主要是對請求和相應的處理。 指定 Filter攔截型別 web.xml配置: <filter> <filter-name>

web.xml配置contextConfigLocation引數作用

如果在web.xml裡給該Listener指定要載入的xml,如: xml程式碼如下:        contextConfigLocation          classpath:applicationContext.xml 則會去載入相應的xml,而不會去載入/WEB-INF/下的app

web.xml,標籤的作用是什麼?

今天看見一個Java專案的web.xml裡面有使用<context-param>標籤,於是百度了一下。將搜到的解決記錄在這裡,方便以後檢視。 1.啟動一個web專案的時候,容器(如:tomcat)會去讀它的配置檔案web.xml。讀兩個節點:<listen

web.xmlservlet ,filter ,listener ,interceptor的作用與區別

一、概念:          1、servlet:servlet是一種執行伺服器端的java應用程式,具有獨立於平臺和協議的特性,並且可以動態的生成web頁面,它工作在客戶端請求與伺服器響應的中間層。最早支援 Servlet 技術的是 JavaS

web.xml的配置,servlet,filter,listener的作用和原理

首先介紹servlet,filter和listen的原理: servlet可以說是動態頁面的基石,現在很多開發都是基於spring等各種框架,所以對servlet的瞭解可能少點,下面先用簡單的例子,說明下servlet的作用 MyFirstServlet.java class MyF

web.xmlcontext-param作用

web.xml的配置中<context-param>配置作用 1. 啟動一個WEB專案的時候,容器(如:Tomcat)會去讀它的配置檔案web.xml.讀兩個節點: < listener></listener> 和 <context-

web.xml的contextConfigLocation在spring作用

在web.xml中通過contextConfigLocation配置spring,contextConfigLocation引數定義了要裝入的 Spring 配置檔案。如果想裝入多個配置檔案,可以在 <param-value>標記中用逗號作分隔符。在web.xml

[Spring]web.xml配置ContextLoaderListener監聽器的作用

在spring的核心配置檔案中,為什麼配置ContextLoaderListener監聽器 <listener> <listener-class>org.springframework.web.context.ContextLoaderLi

web.xmlcontext-param,listener等作用及載入過程

<context-param>的作用: web.xml的配置中<context-param>配置作用(可在listener和servlet中使用,而 ContextLoaderListener及contextConfigLocation則由spri

(轉)web.xml的contextConfigLocation在spring作用

param 不存在 new xml配置 prope alt 圖片 變量 -s 一、Spring如何使用多個xml配置文件   1、在web.xml中定義contextConfigLocation參數,Spring會使用這個參數去加載所有逗號分隔的xml文件,如果沒有這個參數

java web 使用load-on-startup標籤建立跟隨Tomcat同時執行的類

在一個小的專案當中,需要一個類在tomcat 啟動時跟隨Tomcat一同啟動並執行。在伺服器開始就開始,在伺服器結束就結束。 第一次想到的是在jsp頁面嵌入java程式碼,使用並不友好,需要訪問才可以執行java類。 現在使用另一種方法進行啟動java 類 建立一個serv

web.xml作用及配置

<context-param> <param-name> xxx<param-name> <param-value&g

web.xmlDispatcherServlet的作用

DispatcherServlet是前端控制器設計模式的實現,提供SpringWebMVC的集中訪問點,而且負責職責的分派,而且與spring IOC容器無縫整合,從而可以獲得Spring的優勢。其主要職責是排程工作,本身用於控制流程,具體為:1.檔案上傳解析,如果請求型別是