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