The difference between Spring Aop, interceptors, filters

Source: Internet
Author: User

Filter Filters: Blocks Web Access URL addresses.
Interceptor Interceptor: Intercepts the URL at the end of the. Action, blocking access to the action.
Spring AOP Interceptor: can only intercept access to spring management beans (Business layer Service)
----------------------------------------------------------------------------
Spring AOP
Spring AOP, an implementation of AOP, uses proxy mode.
Filter
Filter is the specification of the Java EE, and Servlet2.3 begins to introduce/implement the responsibility chain pattern. Filter can be used to set character sets, control permissions, control steering, and so on. Filter is also an implementation of AOP.
Interceptor
Interceptor (Interceptor) is the concept in Struct2. is also an implementation of AOP.
Filter and Interceptor Contact and difference
1. Interceptors are Java-based reflection mechanisms that use proxy mode, and filters are based on function callbacks. 2. The interceptor does not rely on the servlet container, and the filter relies on the servlet container. 3. The interceptor can only work on the action, and the filter works on almost all requests (which can protect resources). 4. The interceptor can access the action context, the object inside the stack, and the filter can not.? 5. Order of execution: Filter before-intercept money-action processing-after interception-after filtering.
----------------------------------------------------------------------------
The difference between interceptors and filters:
1, the Interceptor is based on the Java reflection mechanism, the filter is a Java-based function callback
2. Interceptors are not dependent on servlet containers, and filters depend on servlet containers
3. Interceptors can only work on action requests, and filters work on almost all requests
4. The interceptor can access the action context, the object in the value stack, and the filter cannot access
5, in the action life cycle, the interceptor can be called multiple times, the filter can only be used in the servlet dissolve initialization is called once
6, the Interceptor can get the various beans in the IOC container, filter does not work, in the interceptor injected a s Ervice can invoke logical business


Interceptors:
The filters in the servlet filter filter is a unified set encoding, simplifying the operation, but also to make logical judgments, such as whether the user has logged in, have access to the page and so on. It is launched with your web app, initialized once, and can intercept requests later, only when your web app is stopped or redeployed
Filter:
Interceptors are applied in aspect-oriented programming, either by invoking a method before your service or a method, or by invoking a method after the method. Is a Java-based reflection mechanism. Interceptors are not configured in Web. XML, such as struts in Struts.xml,
Summarize:
1. Filter: The so-called filter is used to filter the name, in the Java Web, your incoming request,response filter out some information in advance, or set some parameters in advance, and then passed into the servlet or struts action for business logic, such as filtering out illegal URLs (not login.do address requests, if the user does not log on to filter out), or in the servlet or struts before the action of the uniform set of character sets, or to remove some illegal characters (chat room often used, some curse words). The filter process is linear, and after the URL has been checked, the original process continues to execute downward, being received by the next filter, servlet, and so on.
2.java interceptors are mostly used on plug-ins, such as Hivernate Spring struts2, and so on, which is somewhat similar to slicing-oriented technology, before it is used to declare a paragraph in a configuration file as an XML file.

The difference between Spring Aop, interceptors, filters

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.