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.