[Learn Struts2 step by step] -- Struts2 workflow and struts2 Workflow

Source: Internet
Author: User

[Learn Struts2 step by step] -- Struts2 workflow and struts2 Workflow

In the previous blog, I used a simple example to get a brief understanding of the struts2 process. This blog continues.

When a user wants to log on to a website, enter the user name and password, and click Login, the following processes will be triggered:

1. The request will go through a series of filters, and FilterDispatcher is called.

2. FilterDispatcher asks ActionMapper to determine whether the request needs to call LoginAction.

3. If you decide to call LoginAction, FilterDispatcher will send the request processing to ActionProxy.

4. The agent creates an ActionInvocation instance by querying the configuration file.

5. Call a series of interceptors

6. After the Action is executed, the result is returned. ActionInvocation is responsible for finding the corresponding return results based on the configuration in struts. xml and returning them to JSp.

 

Is the coarse-grained call relationship in the class:

 


 

Use the call relationship of several important classes in the sequence diagram:


 

The workflow of Struts2 is a core content of Struts2. Other content is also centered on its workflow, which is based on the extension. This blog is also a more detailed theoretical description of the previous article.


Struts2 Workflow

The main workflow of struts2 is as follows:
First, an http request will first enter ActionContextCleanup (such as clearing the value stack, but will leave its own, such as session and Attribute). Its role is shown in the brackets.
Next, take some filters, and then enter the well-known struts2 general control FilterDispatcher
After passing through the above layers, the system will enter ActionMapper to determine whether the request needs to be processed by struts2. If necessary, it will be taken over by ActionProxy. Through configuration management, we can find our struts. xml, and then enter the actual Action
Invocation goes through our interceptor in sequence to enter the action, and then selects the page we want based on the returned result. The values in the first half of the devalued stack of the interceptor are displayed on the page through tags, finally, the response is generated, as shown in the following figure.
This figure is summarized by myself. The one with more colors is the official image of struts2, which only adds comments.
In struts2, there are some applications. For example, as shown in the figure, When you click the Add button, an action is triggered to the web server, the server accepts the request, and the corresponding web container, we can find our webapp Based on the context and find the overall configuration file web. xml, based on the configuration in it to determine who to process the action, find the filter, reflect the creation class, callback init, read the struts configuration file of struts2. xml, find action according to namespace, reflect and create action class instance, return to the execute method, find the corresponding result and switch to the next page, where the dotted box is short for the right image




Struts2 workflow?

The process of requests in the Struts2 framework is roughly divided into the following steps:
1. The client initializes a request pointing to the Servlet container;
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 to call an Action.
4. If ActionMapper decides to call an Action, FilterDispatcher submits the request processing to ActionProxy.
5. ActionProxy asks 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 a JSP or FreeMarker template to be represented (but not always, or another Action chain. You can use the tag inherited from the Struts2 framework in the Process of representation. ActionMapper needs to be involved in this process

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.