An overview of the loading order and precedence of the Java EE container objects

Source: Internet
Author: User

I. Overview

    • The Web container is primarily guided by the life cycle of three container objects, namely: Listener/filter/servlet. The general overview is as follows:

      At the same time, there is a configuration node: Context-param, which is used to provide ServletContext with key-value pairs, which are application context information. Our listener, filter, and so on are used to initialize the information in these contexts, loading the order such as:

When ①, loading servlets, there are two kinds of cases: loading at startup, lazy loading.

    • Load at startup
      Simply add a node when configuring the servlet, where the lower <load-on-startup>1</load-on-startup> the value, the higher the priority. ( special Note: The minimum value is 0, negative values are considered lazy loading)
    • Lazy Loading
      That is, the container finishes booting, and the specified servlet is initialized when the response corresponds to the first request. corresponding to the boot load situation, if there is no Configuration node information (load-on-startup) or the node information is negative when the corresponding lazy loading.

②, Filter

    • In Web. XML, you can certainly define multiple filter, a configuration section related to filter is filter-mapping, it is important to note that for the filter and filter-mapping configuration sections with the same Filter-name, fil The ter-mapping must appear after the filter, or the corresponding filter-name is undefined when parsing to filter-mapping. When each filter is initialized at the start of the Web container, it is initialized in the order in which the Filter configuration section appears, and when the request resource matches multiple filter-mapping, the filter interception resource is invoked in the order in which the Filter-mapping configuration section appears in sequence D The Ofilter () method.

③, Listener

    • The order of precedence declared in Web. XML is the order of loading.

An overview of the loading order and precedence of the Java EE container objects

Related Article

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.