Configure filter Annotation

Source: Internet
Author: User

Servlet3.0 uses @ webfilter to define a class that implements the javax. servlet. Filter interface as a filter component. Use@ WebfilterAnnotation configuration simplifies the complexity of configuring filters in Web. xml.

 
@ Webfilter (filtername = "myfilter", urlpatterns = "/images/*") public class myfilter implements filter {......

You can also specify multiple filtering modes.

 
@ Webfilter (filtername = "myfilter", urlpatterns = {"/imageservlet", "/images/*. jpg "})
 
 

As we all know. when configuring filter in XML, you can specify which filter is executed first and which filter is executed later. This is done through each filter-mapping on the web. the order in XML. When you configure the filter through annotations, there are no specific commands to configure the sequence of filter execution. Determine the sequence of filter execution based on the alphabetical order of the filter class name.

Let's talk about the order of filter configuration. Suppose there are two filters, filter1 and filter2. Filter1 is the filter that processes exceptions in a centralized manner, and filter2 is the filter that processes the encoding. If filter2 may throw an exception and the thrown exception needs to be handled by filter1, should filter1 be configured first or filter2 be configured first? Experiments show that filter1 should be configured in front. We can understand this question in this way. We can only install the filter1 processing exception filter to handle the exceptions generated in the filter.

 

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.