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


我們在web.xml中配置servlet的時候會有個屬性<load-on-startup></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.
意思大概:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM