SpringMVC summary (18)-the execution order of multiple filters that intercept the same request

Original link

1. When we set multiple filters for a resource, these filters form a Filter chain structure.
  When the doFilter method of a filter is executed, the chain.doFilter() is called. If there is an interceptor (filter), continue to execute the doFIlter method of the next filter, and
  if there is no filter after that, the request is released. It is equivalent to calling the service() method of the target resource.

   The doFilter() method is used to call the next filter in the Filter chain. If the current filter is the last filter, the request is sent to the target resource.
2. When there are multiple filters, the filter at the top of <url-pattern> in web.xml is executed first.

3. <dispatcher> tag
  After loading the configuration filter class in web.xml, see the previous article to create a Filter for details. There is a <dispatcher> tag in the <url-pattern> tag to set the request method.
  If not set, the default intercepted request is request. When the forwarded request arrives, the filter cannot filter it.
  If you want to intercept the forwarded request web resource. Just set the method to FORWARD in <dispatcher>. At this time, the
  requested web resource cannot be intercepted. Of course, you can write multiple <dispatcher> in <url-pattern>, and
  set the method to REQUEST.

  If you want to intercept the dynamic include in jsp, write another <dispatcher> with the
  method set to INCLUDE.

Guess you like

Origin blog.csdn.net/lsx2017/article/details/114004491