http://www.blogjava.net/xzclog/archive/2011/09/29/359789.html

如下一段配置,熟悉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代表的是优先级,而非启动延迟时间。

为什么不是true和false呢?这是因为如果我们在web.xml中设置了多个servlet的时候,可以使用load-on-startup来指定servlet的加载顺序,服务器会根据load-on-startup的大小依次对servlet进行初始化。不过即使我们将load-on-startup设置重复也不会出现异常,服务器会自己决定初始化顺序。

如下题目:

2.web.xml中不包括哪些定义(多选)

a.默认起始页

b.servlet启动延迟时间定义

c.error处理页面

d.jsp文件改动后重新载入时间

答案:b,d

通常大多数Servlet是在用户第一次请求的时候由应用服务器创建并初始化,但<load-on-startup>n</load-on-startup>   可以用来改变这种状况,根据自己需要改变加载的优先级!

【转】web.xml中load-on-startup的作用的更多相关文章

  1. web.xml中<welcome-file-list>标签不起作用

    之前也都提到过,web.xml会通过<servlet>和<servlet-mapping>来确定url和指定contoller文件,乃至于jsp页面的联系. 但是有一个< ...

  2. web.xml中的welcome-file-list不起作用

    今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...

  3. web.xml中welcome-file-list的作用

    今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...

  4. 【Servlet】web.xml中welcome-file-list的作用

    今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...

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

    如下一段配置,熟悉DWR的再熟悉不过了:<servlet>   <servlet-name>dwr-invoker</servlet-name>   <ser ...

  6. 详解web.xml中元素的加载顺序

    一.背景 最近在项目中遇到了启动时出现加载service注解注入失败的问题,后来经过不懈努力发现了是因为web.xml配置文件中的元素加载顺序导致的,那么就抽空研究了以下tomcat在启动时web.x ...

  7. web.xml中load-on-startup的作用(转)

    web.xml中load-on-startup的作用 如下一段配置,熟悉DWR的再熟悉不过了:<servlet>   <servlet-name>dwr-invoker< ...

  8. web.xml中load-on-startup的作用,web应用写一个InitServlet,这个servlet配置为启动时装载

    如下一段配置,熟悉DWR的再熟悉不过了:<servlet>   <servlet-name>dwr-invoker</servlet-name>   <ser ...

  9. web.xml中load-on-startup

    <servlet> <servlet-name>SystemInit</servlet-name> <servlet-class>sjgl.system ...

随机推荐

  1. WebException获取详细内容 记录

    http://bbs.csdn.net/topics/390883361 来自此处. 问题.某个接口.返回错误消息用的是400.所以必须知道具体的内容. using System; using Sys ...

  2. Death to Binary? 分析模拟

    /** 题目:Death to Binary? 链接:https://vjudge.net/contest/154246#problem/T 题意:略. 思路: 注意事项: 给的字符串存在前导0: 存 ...

  3. grails 解决emoji标签存入mysql

    domain将存储emoji属性类型设置位byte[] class UserTest { byte[] nameBytes //存储emoji表情字段 Date dateCreated //grail ...

  4. OC 字符串出来

    //1.获取字符串的长度 NSString * str = @"abcd"; NSUInteger length = [str length]; //str.length; NSL ...

  5. 第一百九十四节,jQuery EasyUI,Droppable(放置)组件

    jQuery EasyUI,Droppable(放置)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Droppable(放置)组件的使用方 ...

  6. Spring Hello World 实例

    Hello World 实例 让我们使用 Spring 框架开始实际的编程.在你开始使用 Spring 框架编写第一个例子之前,你必须确保已经正确地设置了 Spring 环境,正如在 Spring—— ...

  7. iOS-毛玻璃、navigationBar滑动颜色渐变

    1.毛玻璃实现 iOS8以上,官方提供了系统方法实现毛玻璃,代码如下: // iOS8 UIVisualEffectView UIImageView *bgView = [[UIImageView a ...

  8. OpenCV学习笔记十四:opencv_objdetect模块

    一,简介: 该库用于目标检测.

  9. 服务器之FRU

    EEPROM是server主板上的电可擦除可编程只读存储器, 里面存储了FRU data, 包括制造商,产品型号,产品序列号,资产序列号等信息,为厂商和客户提供资产信息管理. 所以正确的FRU格式以及 ...

  10. 【BZOJ3638】Cf172 k-Maximum Subsequence Sum 线段树区间合并(模拟费用流)

    [BZOJ3638]Cf172 k-Maximum Subsequence Sum Description 给一列数,要求支持操作: 1.修改某个数的值 2.读入l,r,k,询问在[l,r]内选不相交 ...