Servlet配置load-on-startup

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
metadata-complete="true" version="3.0">
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <!--
  Element : 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. 
 (这句话的含义是说如果设置了这个元素的值,那么在web应用程序启动的时候,会实例化这个servlet
 并且调用其中的init方法) 
 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.
 (上面的含义表示如果负数或没有当前的值设置,则某个servlet无论何时在被选择的时候才加载,包括上面的
 instantiated和init)
 The container may choose the order of loading of servlets with the 
 same load-on-start-up value.(容器可以选择一个相同的value去加载servlet)

Data Type : load-on-startupType
Enumerated Values :  
   -->
  <servlet>
    <servlet-name>HelloworldServlet</servlet-name>
    <servlet-class>com.ghsy.HelloworldServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloworldServlet</servlet-name>
    <url-pattern>/Helloworld</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>LifecycleServlet</servlet-name>
    <servlet-class>com.ghsy.LifecycleServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>LifecycleServlet</servlet-name>
    <url-pattern>/lifecycle</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>InitServlet</servlet-name>
    <servlet-class>com.ghsy.InitServlet</servlet-class>
    <init-param>
      <param-name>参数1</param-name>
      <param-value>value1</param-value>
    </init-param>
    <init-param>
      <param-name>参数2</param-name>
      <param-value>value2</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>InitServlet</servlet-name>
    <url-pattern>/init</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>GenericServletDemo</servlet-name>
    <servlet-class>com.ghsy.GenericServletDemo</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>GenericServletDemo</servlet-name>
    <url-pattern>/generic</url-pattern>
  </servlet-mapping>
</web-app>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hymKing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值