The interceptor is the basis of Struts2. What is the interceptor?

Source: Internet
Author: User
Tags aop

Interceptor, used in AOP (Aspect-Oriented Programming) to intercept a method or field before it is accessed, and then add some operations before or after it. Interception is an implementation policy of AOP.

What is the meaning of the Chinese document in Webwork ?? An interceptor is an object that dynamically intercepts Action calls. It provides a mechanism for developers to define the code to be executed before and after an action is executed, or to prevent it from being executed before an action is executed. It also provides a way to extract reusable parts of an action.

When talking about interceptor, should we know another word ?? Interceptor Chain (called Interceptor Stack in Struts 2 ). The interceptor chain is to link the interceptor into a chain in a certain order. When accessing intercepted methods or fields, the interceptor in the interceptor chain will be called in the order defined previously.

Implementation principle

The interceptor implementation of Struts 2 is relatively simple. When a request arrives at the ServletDispatcher of Struts 2, Struts 2 searches for the configuration file, instantiates the relative interceptor object based on the configuration, and then concatenates the object into a list ), call the interceptor in the list one by one, as shown in Figure 1.

 
Figure 1 sequence of interceptor calls

Existing interceptor

Struts 2 provides you with a wide range of interceptor implementations. You can go to the struts2-all-2.0.1.jar or struts2-core-2.0.1.jar package to view the configurations about the default interceptor with the interceptor chain.

<

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.