Interceptors are a core part of the STRUTS2 framework, and many of the framework's functions are built on interceptors. STRUTS2 uses built-in interceptors to accomplish most of the operations within the framework, and interceptors are specific implementations of AOP (aspect-oriented programming) in the STRUTS2 framework.
The following is the process of configuring a custom interceptor.
Suppose a function is required to print out the HelloWorld in the console before invoking each action, requiring the use of the Struts2 interceptor.
1. Create an action class Myaction.java and a configuration file struts.xml, such as.
2, write Myaction.java to achieve an age attribute.
3, configure struts.
4, set up an interceptor class Helloworldinterceptor.java, custom interceptors must implement interceptor excuses or inherit Abstractinterceptor class.
5. Add Interceptor settings to Struts.xml
6, write success.jsp page
7. Run the project.
The interceptor is complete.
Use of interceptors in Struts2