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.