Through step-by-step encapsulation, we have achieved the basic prototype of struts, and solved the problem of how struts implements MVC. Now we only have the foundation of struts, and learning struts is just getting started, in this article, we need to compare MVC to understand the execution process of struts, and finally go deep into the source code of struts to see what is going on.
MVC
M: business logic. business data can be reused. We often say that JavaBean (in fact, struts does not implement the business layer and cannot implement it)
V: display logic. The same data copy corresponds to multiple display methods. JSP code implementation
C: controls the flow controller and Servlet code implementation.
Let's look at the execution process of the MVC mode through the time sequence diagram, as shown in:
Struts
From the previous blogs, we learned that struts is an open-source Web Application Framework Based on JSP and Servlet. It highly encapsulates MVC, in addition, we encapsulate a struts step by step from MVC.
Directory:
[Advanced SSH] basic principles of STRUTS + simple Logon (2)
[Advanced path to SSH] Step-by-Step reconstruction of MVC to implement the Struts framework-starting from a simple MVC (III)
[Advanced path to SSH] Step-by-Step reconstruction of MVC to implement the Struts framework-encapsulate business logic and redirect paths (4)
[Advanced path to SSH] Step-by-Step reconstruction of MVC to implement the Struts framework-completely remove logical judgment (V)
[Advanced path to SSH] Step-by-Step reconstruction of MVC to implement the Struts framework-improving the transition to the page (6)
First, we will draw a sequence diagram that is consistent with the previous example and is roughly the same as that of MVC. In order to help you understand the whole detailed stream of struts. As follows:
General process:
In-depth source code:
After we understand the basic process of struts, we also need to look at the source code to see whether we learn struts not only for use, but also the true principle of it. If you want to be a good architect, you cannot stop.
The sequence diagram is as follows:
From the above figure, we can find that actionservlet has almost completed all struts functions. Like the MVC controller, actionservlet plays a very important role. Let's analyze it in a more fine-grained manner, as shown in:
From the above flowchart, we can find that requestprocessor plays a crucial role. After intercepting the URL, setting the ing relationship, and reflecting and creating the actionform, setting the value, and then reflecting and creating the action, finally, execute the execute method to complete the redirection. At this time, our ideas are very clear. Below I will summarize the struts Process in my own language.
Struts Process
We have read the basic process of struts and the implementation process of struts through the source code. Below we need To summarize it in our own language.
1) the client sends an HTTP request.
2) According to the Web. xml configuration, this request is received by actionservlet.
3) According to the struts-config.xml configuration, actionservlet first fills the parameters in the request into actionform, then actionservlet sends the request to the action for processing.
4) Whether to verify. If verification is required, the validate method of actionform is called. If verification fails, the system jumps to input. If verification succeeds, the system continues.
5) Action obtains data from actionform and calls the Business Method in the JavaBean (model) to process data.
6) action returns the actionforward object and jumps to the corresponding JSP page or action.
7) return an HTTP Response to the client.
The above process is everywhere. It's okay to have a look. It's annoying to have a look at it. Let's sort it out with a picture:
Summary
Finally, I believe that after the comparison and analysis over the past few times, you are familiar with the basic principles of struts.
Introduction:
In the next blog, we will update some hibernate content, starting with the basic principles, and then setting up a development environment for hibenate, which is a simple example.
[Advanced path to SSH] go deep into the source code and explain the basic implementation process of struts.