1 Working Principle 1.1 System Architecture
Figure 2.1 architecture of struts2.0
1.2 Working Mechanism
For the architecture diagram of the previous section, the following describes the execution process step by step.
? The client initializes a request pointing to a Servlet container (such as Tomcat;
? 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 );
Note: After struts2.1.3, you do not need to configure the ActionContextCleanUp filter. The filter is used to clear the value stack, but struts will leave its own session and Attribute.
? Next, call struts's StrutsPrepareAndExecuteFilter filter. StrutsPrepareAndExecuteFilter asks ActionMapper to determine whether the request needs to call an Action;
Note: struts used the FilterDispatcher filter in the early days. Currently, StrutsPrepareAndExecuteFilter is widely used. For the name, prepare and execute indicate that they are prepared to refer to the filterinit method, that is, the configuration is imported; the latter indicates that the filtering means that the doFilter method, that is, the request is forwarded to the corresponding action for processing.
? If ActionMapper decides to call an Action, StrutsPrepareAndExecuteFilter will hand over the request processing to ActionProxy;
? ActionProxy queries the framework Configuration file through Configuration Manager and finds the Action class to be called;
? ActionProxy creates an ActionInvocation instance.
? 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.
? 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.
1.3 running sequence diagram
When you sort out this document, you can find a picture on the Internet. Special Loan.