The difference between the interceptor and filter Filter Interceptor's

(1) filter (Filter): When you have a bunch of stuff, you just want to choose something that you comply with certain requirements. Tool definition these requirements, is a filter. (Understood: take a pile of letters B)

(2) interceptor (Interceptor): In an ongoing process, you want to interfere with its progress, or even terminate it for, this is the interceptor to do. (Understand: a pile of letters in his intervention, authenticated fewer points the way to doing something else).

  Interceptor java reflection mechanism is based, and the filter is based on a callback function.
  Interceptor does not rely servlet container, and the filter dependent servlet container.
  Action can only request interceptor function, and the filter can act on almost all the requests.
  Action interceptors can access context, the value of the stack of objects, and the filter can not be accessed.
  In the action of the life cycle, the interceptor can be called multiple times, and the filter can only be called once when the container is initialized.
  Interceptor can acquire IOC container each bean, and the filter will not work, it is very important to inject a service interceptor you can call the business logic.
 
 
1. The filters are JavaEE standard manner using a callback function. Is pretreated before entering the container after the request, not yet entered the Servlet, and returns to the post-processing between the distal end of this request.
chain.doFilter (request, response); call this method as a watershed. In fact the call doService Servlet () method is chain.doFilter (request, response); carried out this method.
 
 
2. interceptor is wrapped in a filter.

  a.preHandle () This method step is performed before the filter chain.doFilter (request, response) method, that is, [System.out.println ( "before ...")] [chain.doFilter (request , response) executed between].

  After b.preHandle () method, before the return ModelAndView be, you can manipulate the contents of the Controller ModelAndView.

  c.afterCompletion () method is returned to step performed before the front end of the filter, i.e. in [chain.doFilter (request, response)] [System.out.println ( "after ...")] between execution.

3.SpringMVC mechanism is different from the Controller Servlet to distribute the request for the same, in fact, this step is performed in the Servlet's service () method. So filters, interceptors, service () method, the order of execution dispatc () method should be such that roughly drew a diagram: In fact, very good test, write a filter, a blocker, then these methods all add breakpoint, all the way down to F8 concluded.

4.SpringMVC mechanism is different from the Controller Servlet to distribute the request for the same, in fact, this step is performed in the Servlet's service () method.

5., SpringMVC mechanism is different from the Controller to distribute requests to the same Servlet, in fact, this step is performed in the Servlet service () method.

6.SpringMVC mechanism is different from the Controller Servlet to distribute the request for the same, in fact, this step is performed in the Servlet's service () method.

 

7. Also, the interceptor vessel is spring, spring is supported,

 

 

 URL: http://blog.sina.com.cn/s/blog_4c890a7f0102xnvq.html

Guess you like

Origin www.cnblogs.com/Tony100/p/11590111.html