First, the STRUTS2 processing process:
- The client generates a HttpServletRequest request, which is submitted to a series of standard filter (filter) build chains (such as Actioncontextcleanup: it is mainly to clean up the actioncontext of the current thread, Dispatcher,filterdispatcher mainly through Actionmapper to determine the need to call that Action,filterdispatcher is the core of the controller, but also the core of the MVC control layer set up).
- The core controller build Filterdispatcher the need to call an action build to handle the HttpServletRequest request based on the settings in the Actionmapper. If Actionmapper decides to invoke an action build, the Filterdispatcher core controller will delegate the processing of the request to the Actionproxy build
- Actionproxy set up the configuration file Struts.xml to get the STRUTS2 framework by configuring manager, and finally find the target action build class that needs to be called. The Actionproxy is then created to create an object instance of the object instance class of the Actioninvocation class that implements the command pattern (this procedure includes invoking the Before () method of multiple interceptor builds before calling the Anction build itself) At the same time, the Actioninvocation build invokes the target action build through proxy mode. However, prior to the call, the Actioninvocation build will load all interceptor builds (interceptor) associated with the target action build based on the settings item in the configuration file.
- Once the action build is complete, the actioninvocation build will get the return result of the object based on the individual configuration items defined by the developer in the Struts2.xml configuration file-The result code for this action (one like Success,input) The target JSP page is then invoked based on the returned result to implement the display output.
- Finally, each interceptor build is executed again (but in the reverse order and at the beginning, and the After () method is called), and then the other filters that are configured in the deployment file that are eventually returned to the system are requested, and if the Actioncontextcleanup filter is already set, Then Filterdispatcher will not clean up the actioncontext information stored in the Threadlocal object. If you do not set the Actioncontextcleanup filter, Filterdispatcher will erase all threadlocal objects.
To be more clear:
1. The client initializes a request to the servlet container.
2. Request through a series of filters (Actioncontextcleanup, Sitemesh)
3.FilterDispatcher is called and asks Actionmapper to decide whether the request needs to invoke an action
4.ActionMapper decided to call the Action,filterdispatcher to hand over the request to Actionproxy.
5. Actionproxy ask the struts configuration file via Configurate Manager to find the action class to invoke
6. Actionproxy Create a Actioninvocation instance
7. The Actioninvocation instance uses the command pattern to invoke the Exeute method of the callback action
8. Once the action is executed, Actioninvocation is responsible for returning the results based on the Struts.xml configuration.
Ii. introduction of the more important classes:
Actionmapper is actually a mapping of httpservletrequest and action invocation requests, and he blocks the action's reliance on Java servlet classes such as request. STRUTS2 its default implementation class is Defaultationmapper,actionmapper a great use can be based on their own needs to design the URL format, it also has a restful concrete implementation.
Actionproxy and Actioninvocation:
An agent for action, created by Actionproxyfactory, does not include an action instance by itself, and the default implementation defaultactionproxy is an action instance held by Actioninvocation. The Actionproxy action is how to get an action, whether local or remote. And Actioninvocation's function is how to execute action, the function of the interceptor is we actioninvocation in the realization.
Configurateprovider and Configuration
Configurationprovider is the parser for the configuration file in Struts2, The configuration file in Struts2 is mainly to implement Xmlconfigurationprovider and its subclass Strutsxmlconfigurationprovider to parse.
STRUTS2 Request Processing:
Java Framework---process of Struts2