为什么我们在使用struts 1.x时在web.xml中编写<load-on-startup> 2 </ load-on-startup>?

amo*_*mod 9 java servlets java-ee

我是J2EE的新手,考虑到同样的问题,请回答.当我们使用struts时为什么要load-on-startup>2</load-on-startup>在servlet标签中写< ?这个标签是什么意思?如果有什么东西加载秒,那么先加载什么 另请提供一些链接,它解释了structs-config.xml的所有标签

Ayu*_*man 10

load-on-startup告诉servlet容器在服务器启动时加载指定的资源.如果有多个load-on-startup标记,您看到的数字会告诉启动顺序.

<load-on-startup>1</load-on-startup>
<load-on-startup>2</load-on-startup>
Run Code Online (Sandbox Code Playgroud)

将导致首次加载启动时加载的资源1.这是为了在存在依赖性时控制加载顺序.查看解释加载顺序的servlet规范.

我在下面的评论中提到的答案(参考http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd):

  <xsd:element name="load-on-startup"
           type="javaee:load-on-startupType"
           minOccurs="0">
    <xsd:annotation>
      <xsd:documentation>

        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.

      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
Run Code Online (Sandbox Code Playgroud)

仔细阅读文档.


JB *_*zet 8

请参阅http://struts.apache.org/1.x/userGuide/configuration.html.

load-on-startup表示必须在启动webapp时加载和初始化servlet(即,只要部署它,就不必等待对servlet的请求).该数字表示初始化的顺序.如果另一个servlet有1,它将被加载.如果另一个有3,它将被加载.