Configuration of servlet, spring, filter, and listenr in Web. xml

Source: Internet
Author: User

Web. xml files generally include servlet, spring, filter, and listenr configuration.
Loading Order will affect spring bean calls.
Listener> filter> servlet> spring
If bean is used in the filter, you can change spring loading to listener.

<Listener>
<Listener-class>
Org. springframework. Web. Context. contextloaderlistener
</Listener-class>
</Listener>

 

 

Their internal execution sequence should also be noted.

Garbled characters caused by the filter execution sequence of Web. xml

The cause of the bug is the following lines of Web. xml:
<Filter-mapping>
<Filter-Name> securityfilter </filter-Name>
<URL-pattern> *. DO </url-pattern>
</Filter-mapping>

<Filter-mapping>
<Filter-Name> characterencoding </filter-Name>
<URL-pattern> *. DO </url-pattern>
</Filter-mapping>

<Filter-mapping>
<Filter-Name> characterencoding </filter-Name>
<URL-pattern> *. jsp </url-pattern>
</Filter-mapping>

According to the servlet2.3 specification, filter execution is performed according to the Web. the filter-mapping configured in XML is executed sequentially, so the above configuration will result in *. do URL requests are first processed by the securityfilter filter. At this time, no encoding is performed, and garbled characters are generated. It is useless to process the following filters.

Modify the filter-mapping order as follows:

<Filter-mapping>
<Filter-Name> characterencoding </filter-Name>
<URL-pattern> *. DO </url-pattern>
</Filter-mapping>

<Filter-mapping>
<Filter-Name> characterencoding </filter-Name>
<URL-pattern> *. jsp </url-pattern>
</Filter-mapping>

<Filter-mapping>
<Filter-Name> securityfilter </filter-Name>
<URL-pattern> *. DO </url-pattern>
</Filter-mapping>

 

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.