web.xml:load-on-startup标签

1.load-on-startup标签,有什么作用?



2.举例,

  <servlet>
    <servlet-name>userdatabase</servlet-name>
    <servlet-class>addressbook.UserDatabaseServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name> 
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>pathname</param-name>
      <param-value>/WEB-INF/userdatabase.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup> <!-- 1.启动tomcat时,就要加载servlet类,容器自动调用init()方法,初始化一些信息  2.如果一个servlet类没有配置该标签的话,那么只有当首次请求该servlet时,才会加载该servlet类(当然,也会调用init()方法,初始化一些信息)    注意:一个servlet类,只会被容器加载一次;它的init()方法,在加载的时候自动被容器调用,而且初始化方法只会被调用这一次,以后不会被调用,除非重启tomcat————但是,业务方法可以被多次调用!!! -->
  </servlet>
  
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>


你可能感兴趣的:(web.xml:load-on-startup标签)