How struts2 works

Source: Internet
Author: User
[Composition] components of the struts2 framework

1. actionmapper and actionmapping
The Org. Apache. struts2.dispatcher. Mapper. actionmapper interface provides a ing between HTTP requests and action call requests. When an HTTP request is given, actionmapper searches for the corresponding action based on the request URI. If yes, an actionmapping describing the action call is returned. If no, null is returned.
Actionmapping is essentially a data transmission object, which combines the action class with the detailed information of the method to be executed on the mobile phone.

2. actionproxy and actioninvocation
Actionproxy acts as a proxy between xwork and the real action. In the process of executing the action through the framework, because the proxy is used instead of directly operating the object, therefore, additional code such as the interceptor and result can be encapsulated in the proxy.
Actionproxy holds the actioninvocation object. Actioninvocation indicates the current status of action execution. It holds the Interceptor (in order), Action instance, result ing (from result to result instance ing) and actioncontext.

3. actioncontext
Actioncontext is the context of Action execution. Each context is equivalent to the container of a group of objects required for an action execution, such as Session, application, parameters, and locale.
Actioncontext is local to the thread, which means that the value stored in actioncontext is unique for each thread. Therefore, for an action, if you want to obtain data from the actioncontext, you do not need to worry about thread security.
The complete Class Name of actioncontext is com. opensymphony. xwork2.actioncontext.

4. objectfactory
Com. opensymphony. xwork2.objectfactory is responsible for building core framework objects (interceptor, action, result, etc ). You can register your own objectfactory implementation to control the instantiation of these objects.
You can regard objectfactory as a factory specifically responsible for creating objects in the struts2 framework. subclasses derived from this factory class can be instantiated in different ways. The struts2 framework does not assign this role to objectfactory. By providing custom implementation of objectfactory, you can easily integrate the framework with IOC containers (such as spring, Pico, and plexus.

5. Result
Com. opensymphony. xwork2.result interface indicates the result after the action is executed. Each action execution returns a string-type result code, which is used to select the corresponding result from the configured result element list. Result configuration in the Struts. xml file

 

[Principle] Working Principle of the struts2 framework

Struts2 is not a strange Web framework. It is centered on the design idea of webwork and absorbs the advantages of struts1. It can be said that

Struts2 is the combination of struts1 and webwork.

Working principle of struts2:

The process of a request in the struts2 framework is divided into the following steps:

1. The client sends a request to the servlet container (Tomcat );

2. This request will pass through several filters in the figure and finally reach the filterdispatcher filter.

3. The filter filterdispatcher is the heart of the struts2 framework. when processing a user request, it and the request work together to access struts2.

. When a Web container is started, the struts2 framework automatically loads parameters in the configuration file and converts them to corresponding classes.

For example, configurationmanager, actionmapper, and objectfactory. Configurationmanager contains one of the configuration files.

Some basic information. actionmapper has the configuration information of the action. All objects (action, results,

Interceptors, etc.) are created through objectfactory. The filter will query the actionmapper class to find the request.

Action.

4. If the action to be called is found, the filter will send the request processing to actionproxy. Actionproxy is the proxy object of action.

. Actionproxy queries the framework configuration file through configurationmanager and finds the action class to be called.

5. actionproxy creates an actioninvocation instance. Actioninvocation is under the actionproxy layer, which indicates

The execution status of the action, or the execution steps of the action it controls. It holds action instances and all interceptors.

6. The actioninvocation instance is called in the naming mode. 1. During actioninvocation initialization, the action phase is loaded according to the configuration.

All interceptor. 2. Execute interceptor when calling action implementation through actioninvocation. Invoke method. In

Before and after the action is called, it involves the call of the relevant Interceptor (intercepetor.

7. Once the action is executed, actioninvocation is responsible for finding the corresponding return result based on the configuration in struts. xml. Returned results

Usually (but not always, or another action chain) a JSP or freemarker template to be represented. In the table

In the struts2 framework, the inherited labels can be used.

 

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.