Tomcat ----- loading sequence of web. xml, tomcat ----- web. xml

Source: Internet
Author: User

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.

 

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.