Struts
When I got started with this framework, I was wondering why it was struts, not craigframework. Structure and support.
Why does struts work?
In the struts in action book, Struts developers also talk about it. With MVC, we still need such a framework to support development, because with JSP, model, and EJB, what else do we need to deal with this process?
Principle
First, start the Tomcat server, and then start the Tomcat server. The project deployed in Tomcat is started, and the struts servlet is instantiated according to the Web. xml file under the project; and the struts-config.xml file is loaded. After the Web Client sends a request to Tomcat, the request and response objects are instantiated. Call the dopost Method for post submission, request the actionservlet, and call the dopost method.
Some illustrations:
1. Intercept URL
The process method called in the dopost method uses the URL carried by the request object that passes through all the hardships. Use the processpath method in the requestprocessor class to intercept the URL;
2. Get actionmapping
The intercepted URL then calls the moduleconfigimpl class through processmapping of requestprocessor to read the nodes in the servlet-config.xml and set the corresponding data to the actionmapping object.
3. instantiate actionform
There is a name for the corresponding actionform in the struts-config.xml. Through this name, we first look for it in the session or request. If there is a direct return, the corresponding value is not obtained through name and the corresponding class instance is obtained through reflection.
4. Set form data
Set form data to actionform
5. Create and execute action
Call processactioncreate of requestprocessor to create an action. The creation process is similar to that of actionform. Execute the execute method, call the business logic, return the response object, forward it to the JSP page, and render the page.
Actionform: A JavaBean associated with actionconfig. parameters are automatically initialized before the corresponding action is called, and verified data is filled with the corresponding attributes of the class.
Advantages:
1. Struts is equivalent to isolation. Only data that passes through the actionform can be called by subsequent actions. Some isolation and filtering are performed.
2. Establishing a bridge between HTTP requests and actions is also a kind of service-oriented hierarchy and decoupling. Separate processing of form data.
Disadvantages:
1. When there is only one or several actionforms, this solution certainly solves and responds to the problem. When hundreds of actionforms appear later, this method of integrating data for each request affects the efficiency. This method is not only prone to problems during writing, but is not conducive to subsequent maintenance. Therefore, the next struts1.x has a dynaactionform solution for this problem. Configure the relevant attributes in the XML file. In this way, you can only modify and write the settings for config.
Descending Order
Struts serves as a bridge between JSP and model. A powerful control and forwarding data center with better performance is actually a controller with MVC as the core. Therefore, some of its established standards, such as: You need to specify the hyperlink format (*. Do, *. Action) to request to the actionservlet. Struts automatically creates, assembles, verifies, and finally processes the actionform corresponding to the action object. In this way, the action can directly obtain the required data from the actionform bean and render it to the final JSP.
struts 1.x principles