Research and application of Struts framework based on MVC pattern

Source: Internet
Author: User

The Distributed enterprise application software has complex structure and involves many kinds of technology, which puts forward a high demand for the design and development personnel. In this case, it is necessary to design and develop the software using the design pattern-reusable design scheme. MVC pattern has been proved to be a successful software design pattern, this paper mainly discusses an application framework of MVC pattern ――struts, and demonstrates the method of implementing the MVC pattern with Struts framework through an example.

MVC design Pattern

MVC (Modle-view-controller, model-View-Controller) mode is a software design pattern designed by Xerox PARC in the 1980s for the programming language Smalltalk-80, which has been widely used so far, It is recommended as the Sun Java Platform Design model, which provides an excellent design model for the development of interactive application systems, and is welcomed by more and more developers.

The MVC pattern consists primarily of 3 parts: models, views, and controllers, as shown in Figure 1.

Figure 1 MVC Pattern Framework

The model represents business logic and business rules, and has the most processing tasks in the three parts of MVC. It can use component technologies such as JavaBean and EJB to handle access to the database. A model can provide data for multiple views. Because the code applied to the model can be reused by multiple views only once, it reduces the duplication of the code.

The view is displayed on the screen. After the model has been manipulated, the result is displayed through the view. There is actually no real processing happening in the view, just as a way of outputting data and allowing the user to manipulate it.

The controller is used to manage user interaction with the view. Once the user wants to process the model, it cannot execute the model directly, but it is realized indirectly through the controller. The controller can take a value from the view, and then pass the corresponding value to the model for processing. The controller accepts input from the user and invokes the model and view to fulfill the user's needs.

From the above, the MVC pattern process is: first, the controller to receive the user's request, and decide which model should be called to process, and then the model with business logic to handle the user's request and return data, the last controller in the corresponding view returned data, and through the expression layer presented to the user.

MVC itself is a very complex system, so using MVC to implement Web applications, it is best to choose a ready-made MVC framework, under which to develop, so as to achieve a multiplier effect. There are a lot of MVC frameworks available now, because struts has a complete document and is relatively simple, so it's easier to develop an MVC system with it.

Struts Framework

Struts is an open source project for the Apache organization. Struts is a better MVC framework that provides the underlying support for developing an MVC system, with the main technology being servlet,jsp and custom tag library. The basic composition is shown in Figure 2.

Fig. 2 Struts frame diagram

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.