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.
<