Struts (II)-Basic Principles of Struts Framework Implementation

Source: Internet
Author: User

PreviousArticle, We introduced the basic principles of the MVC Framework, and pointed out that there are a large number of if... Else problems. Today we will introduce the Struts framework to solve this problem.

First, let's take a look at the rough sequence diagram:

Actionservlet is a central controller responsible for URL or distribution in the collection area;

Actionform is responsible for collecting form data, and Struts converts form data to the corresponding data type.

Action is the business layer controller.

The above is the general implementation of Struts. The following describes the execution process of the Struts framework:

1. The client sends a request to Tomcat;

2. Tomcat will create httprequest and httpresponse instances and call the doget or dopost methods of the central controller based on the Method Request Method;

3. The central controller of actionservlet is responsible for intercepting URLs, obtaining configuration information based on the intercepted URLs, and placing the information in the Action tag in actionmapping.

4. Search for actionform Based on the name in actionmapping. If actionform is configured, search for it in request or session. If an actionform already exists in request or session, return; if it does not exist, the created actionform will be created based on the complete path of the actionform Using Reflection, and then put the created actionform in reqeust or session.

5. First, execute the reset method in actionform to reset it, then obtain the name of all input fields in the form, and then call request. getparametervalues (), get the corresponding value based on the name, and put all the data in the form into a map. The key in map is the name of the input field of the form, the value of the input field (String Array) of the value form of map. Next, call a third-party component beanutils to set the value in map to actionform according to the setter method in actionform.

6. Search in map based on the complete Class Name of the action. If the action exists, the action object is returned. Otherwise, it is created based on the complete name of the Action Class Using Reflection, then, place the created action in map. Therefore, the struts1 action is single-instance and has thread security issues.

7. Execute the execute method in the user-defined action, pass actionmapping, actionform, request, and response to the past, and return actionforward to actionservlet.

8. Complete the redirection Based on the returned actionforward.

The above is the basic implementation of the struts 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.