Detailed explanation of the loading sequence of web. xml components

Source: Internet
Author: User
In the process of configuring project components, it is necessary to understand the order in which Tomcat loads components. For example, some frameworks such as Quartz clusters require database support, and database loading must be prior to framework component loading. In the process of configuring project components, it is necessary to understand the order in which Tomcat loads components. For example, some frameworks such as Quartz clusters require database support, and database loading must be prior to framework component loading.

After checking and debugging, we found that the loading sequence of the web. xml component is: context-param-> listener-> filter-> servlet (the same type is executed in writing order ).

Analysis of common web. xml components:

 
  WEB application name
  WEB Application Description
  The context-param element declares the initialization parameters in the application scope.
  
  
   
    
ContextConfigLocation
   
   
    /WEB-INF/applicationContext. xml,/WEB-INF/action-servlet.xml
   
  
  The Filter associates a name with a class that implements the javax. servlet. Filter interface.
  Once a filter is named, use the filter-mapping element to associate it with one or more servlet or JSP pages.
  The event listener is notified when a session or servlet environment is created, modified, or deleted. The Listener element specifies the event Listener class. For example, Log4j, a widely used listener and
  
  
   
    
Org. springframework. web. context. ContextLoaderListener
   
  
  When you specify initialization parameters or custom URLs to the servlet or JSP page, you must first name the servlet or JSP page. The Servlet element is used to complete this task.
  Generally, the server provides the servlet with the default URL: http: // host/webAppPrefix/servlet/ServletName. However, this URL is often changed so that the servlet can access initialization parameters or process relative URLs more easily. When you change the default URL, use the servlet-mapping element.
  If a session is not accessed for a certain period of time, the server can discard it to save memory. You can use the setMaxInactiveInterval method of HttpSession to explicitly set the timeout value for a single session object, or use the session-config element to specify the default timeout value.
  The MIME-mapping element provides this guarantee if a Web application wants to assign a specific mime type to a specific file.
  Indicates which file the server uses when it receives a URL that references a directory name instead of a file name (in fact, the welcome interface or the entry interface is usually index .*)
  When a specific HTTP status code is returned or an exception of a specific type is thrown, you can specify the page to be displayed.
  Specify an alias for the Tag library Descriptor file. This feature allows you to change the location of TLD files without editing the JSP pages that use these files.
  Declare a resource-related management object.
  Declare the external resources used by a resource factory.
  Specify the URL to be protected. It is used together with the login-config element.
  Specify how the server authorizes users attempting to access protected pages. It is used with the sercurity-constraint element.
  A list of security roles is provided. these roles will appear in the role-name sub-element of the security-role-ref element in the servlet element. Declaring roles separately makes it easier for advanced IDE to process security information.
  Declare environment items of Web applications
 

The above is the detailed explanation of the loading sequence of the web. xml Component. For more information, see The PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.