Tomcat ----- loading sequence of web. xml, tomcat ----- web. xml
The order of loading is irrelevant to their order in the web. xml file. That is, the filter will not be loaded first because the filter is written before the listener.
The loading order in web. xml is: listener-> filter-> servlet
There is also a configuration section: context-param, which is used to provide key-value pairs to ServletContext, that is, application context information. Listener and filter will use the information in these contexts during initialization. Should the context-param configuration section be written before the listener Configuration section? In fact, the context-param configuration section can be written in any location, so the actual loading order is: context-param-> listener-> filter-> servlet
For certain configuration sections, the order in which they appear is related. Take filter as an example. of course, multiple filters can be defined in xml. One configuration section related to the filter is filter-mapping. Note that, in the filter and filter-mapping configuration sections with the same filter-name, the filter-mapping must appear after the filter; otherwise, when the filter-mapping is parsed, the filter-name corresponding to it is not defined yet. When a web container is started, each filter is initialized according to the sequence in the filter configuration section. When the requested resource matches multiple Filters-mapping, filter intercepts resources by calling the doFilter () method in sequence in the filter-mapping configuration section (Servlet is similar to Filter)
Web. the xml loading sequence is: context-param-> listener-> filter-> servlet, the actual Program Calling sequence between the same types is called according to the corresponding mapping Sequence.