In-depth introduction to the Struts Framework (4): Understanding the Struts framework from the MVC code

Source: Internet
Author: User

From the simple introduction to the Struts Framework (I): A simple MVC pattern code example to the analysis of the relationship between MVC and the three layers, this MVC design pattern instance is introduced, go to deep learning Struts Framework (II): refactoring jump paths and business logic in MVC code abstract encapsulation Service Processing and path jump, and then go to deep learning Struts Framework (III): Thoroughly remove the strings in testservlet and the IF-else statement blocks. Remove the IF-else statement blocks and strings. After three articles, we gradually reconstruct an MVC design pattern instance, in fact, a prototype of Struts framework is reconstructed. Let's take a look at what is the Struts framework today.


1. Framework

A framework is a reusable design of an entire or part of the system. It represents a method for interacting between a group of abstract components and component instances. That is to say, the framework is a semi-finished application.

The applications we are facing are generally divided into two parts: one is the business-related components and the other is the business-independent components. We know that the reusability of the components related to the business is very low, which is also obvious. Components unrelated to the business are, service components, such as verification, exceptions, and program process control, are highly reusable. Therefore, when people extract common components from different applications to form a semi-finished application, the framework came into being.


2. Struts Framework

What is the Struts framework? To answer this question, you have to look at the MVC design patterns in the previous three articles, because the Struts framework is a MVC-based framework (if you understand that instance, it is very easy to understand the Struts framework here ).


Struts Framework Structure



The figure above shows the structure of the Struts framework, from left to right, which is V, C, and M. The presentation layer consists of JSP and tag libraries. All requests passed through the Struts framework are accepted by actionservlet (this Struts framework has been encapsulated for me), according to the received request parameters and Struts configuration (struts-config.xml) in actionmapping, send the request to the appropriate action to solve the problem of who made it. They constitute the struts controller. Action is a component that really works in struts applications. Developers usually spend a lot of time here. It solves the problem of what they do, it calls the required business components (models) to complete the application business. The business components solve the problem of how to do it, return the execution result to an actionforward object representing the JSP (or action) that depicts the response to the actionservlet to present the response to the customer.

 

Although a Struts framework instance has not yet been implemented, we have the basis of the previous MVC design mode instance. Let's look at the Struts framework, we found that testservlet in our previous instance has done the actionservlet in struts; adduseraction, deluseraction, modifyuseraction, and queryuseraciton has done the action in struts, and actionform has done the actionform in struts; actionmapping does the actionmapping thing in struts; action_config.xml does the struts-config.xml thing. We can see that our previous MVC design pattern is actually a prototype of the Struts framework, and it also makes us understand that the Struts framework is based on the MVC framework.

 

With the introduction of the three articles, it is much easier to get started with the Struts framework. There are no many concepts, and there is only a simple layer of reconstruction, the most common application is highly encapsulated semi-finished applications, which cannot be simple. This blog understands the structure and nature of the Struts framework. The next blog is going to write a simple example of the Struts framework, so as to gain a deep understanding of the Struts framework from the examples.

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.