Java framework --- Struts2 processing process, java framework --- struts2

Source: Internet
Author: User

Java framework --- Struts2 processing process, java framework --- struts2

1. Struts2 processing process:

  • The client generates an HttpServletRequest request, which is submitted to a series of standard filters to form a chain (such as ActionContextCleanUp: It mainly cleans up the ActionContext, Dispatcher, filterDispatcher mainly uses ActionMapper to determine the Action to call. FilterDispatcher is the core of the controller and also the core of the control layer in MVC ).
  • The core controller sets up FilterDispatcher to determine whether to call an Action to process the HttpServletRequest request based on the settings in the ActionMapper. If the ActionMapper decides to call an Action, the core controller of FilterDispatcher delegates the request processing permission to the ActionProxy.
  • The Configuration file struts of the Struts2 framework is obtained by setting up the ActionProxy through Configuration Manager. xml, and finally find the target Action to be called to form a class, then, the ActionProxy is set up to create an object instance class of the ActionInvocation class that implements the command mode (This process includes calling the Anction build itself before calling multiple interceptor build before () at the same time, ActionInvocation is set up to call the target Action in proxy mode. However, before the call, the ActionInvocation component loads all the Interceptor components (Interceptor) related to the target Action component according to the setting items in the configuration file ).
  • Once the Action formation is completed, the ActionInvocation formation will obtain the returned results of the object based on the various configuration items defined by the developer in the Struts2.xml configuration file-the result code for this Action (like SUCCESS, then, call the target JSP page based on the returned results to display the output.
  • Finally, each interceptor is executed again (but the order is opposite to the start time, and the after () method is called), and the request is finally returned to other filters configured in the system deployment file, if the ActionContextCleanUp filter has been set, FilterDispatcher will not clear the ActionContext information saved in the ThreadLocal object. If the ActionContextCleanUp filter is not set, FilterDispatcher clears all ThreadLocal objects.

More clearly:

1. The client initializes a request pointing to the servlet container.

2. The request goes through a series of filters (ActionContextCleanUp and SiteMesh)

3. FilterDispatcher is called and asks ActionMapper to determine whether the request needs to call an Action.

4. The ActionMapper decides to call the Action. FilterDispatcher submits the request to the ActionProxy.

5. The ActionProxy asks the Struts configuration file through the release Manager and finds the Action class to be called.

6. Create an ActionInvocation instance using ActionProxy

7. The ActionInvocation instance calls in command mode and calls back the exeute method of the Action.

8. Once the Action is executed, ActionInvocation returns the result based on the Struts. xml configuration.

 

II. Introduction of important classes:

ActionMapper is actually a ing between HttpServletRequest and Action call requests. It shields Action dependencies on Java servlet classes such as Request. In Struts2, the default implementation class is DefaultAtionMapper. ActionMapper can be used to design the url format based on its own needs. It also has the specific implementation of Restful.

ActionProxy and ActionInvocation:

An Action proxy is created by ActionProxyFactory, which does not include Action instances. By default, defaactionactionproxy is an Action Instance held by ActionInvocation. ActionProxy is used to obtain the Action, whether local or remote. ActionInvocation is used to execute actions. The Interceptor is implemented in ActionInvocation.

ConfigurateProvider and Configuration

ConfigurationProvider is the parser of the configuration file in Struts2. The configuration file in Struts2 is mainly used to parse XmlConfigurationProvider and its subclass StrutsXmlConfigurationProvider.

Struts2 request processing:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.