Struts2-Architecture Analysis
I. xwork2 --- basics of struts2
The struts2 framework consists of xwork and struts2. Xwork is a command mode framework, which is the basis of struts2. Xwork provides many core functions: IOC (control reversal) Containers, powerful expression language, data type conversion, validation, and pluggable configuration. The core of the xwork framework is action, interceptor, and result. Struts2 extends the basic implementation of these concepts to Support web application development.
In struts2, interceptor is an important concept. The interceptor can execute code before and after the action is called. Most of the core functions of the struts2 framework are implemented as interceptors. Such as type conversion, object assembly, verification, avoiding repeated form submission, and file upload, are all implemented with the help of the interceptor. Collaboration between struts2 interceptor and xwork interceptor.
How struts2 interceptor works
Interaction between struts2 and xwork
Architecture of struts2
The process of a request in the Struts2 framework is roughly divided into the following steps:
1. The client initializes a request pointing to a Servlet container (such as Tomcat;
2. This request goes through a series of filters (these filters have an optional Filter called ActionContextCleanUp, which is very helpful for the integration of Struts2 and other frameworks, such as SiteMesh Plugin );
3. FilterDispatcher is called. FilterDispatcher asks ActionMapper to determine whether the request needs to call an Action;
4. If ActionMapper decides to call an Action, FilterDispatcher submits the request processing to ActionProxy;
5. ActionProxy queries the framework Configuration file through Configuration Manager and finds the Action class to be called;
6. ActionProxy creates an ActionInvocation instance.
7. The ActionInvocation instance uses the naming mode for calling. Before and after the Action is called, the call of the relevant Interceptor (Intercepter) is involved.
8. Once the Action is executed, ActionInvocation is responsible for finding the corresponding return result based on the configuration in struts. xml. The returned result is usually (but not always, or another Action chain) a template of JSP or FreeMarker to be represented. You can use the tag inherited from the Struts2 framework in the Process of representation. ActionMapper is required in this process.