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

咱們在web.xml中配置servlet的時候會有個屬性<load-on-startup></load-on-startup>,這裏主要記一下它的做用,源碼在後續記得好好看一下。web

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.
意思大概:
app

  1. load-on-startup 元素標記容器是否應該在web應用程序啓動的時候就加載這個servlet,(實例化並調用其init()方法)。
  2. 它的值必須是一個整數,表示servlet被加載的前後順序。
  3. 若是該元素的值爲負數或者沒有設置,則容器會當Servlet被請求時再加載。
  4. 若是值爲正整數或者0時,表示容器在應用啓動時就加載並初始化這個servlet,值越小,servlet的優先級越高,就越先被加載。值相同時,容器就會本身選擇順序來加載。
相關文章
相關標籤/搜索