Using struts to develop Web applications based on MVC

Source: Internet
Author: User
Tags cgi web mixed

Introduction to MVC

The MVC pattern is a very idealistic design pattern, and people who have done more than two projects with the MVC pattern have the same experience, and they have thoroughly reformed their previous methods of work. The change in working patterns comes at a painful cost, but now you have a ready-made technical framework that you can use to avoid developing and groping yourself in your project. It is the open source Apache Struts Framework, which provides the best implementation tool for implementing the MVC design pattern.

In this article, we'll take a brief look at the model-view-controller (MVC) design pattern, and in particular, we'll see how to implement the MVC pattern perfectly with the struts architecture. Let's briefly describe the MVC pattern theoretically, and then use our simple example to implement our own MVC architecture. With an understanding of the MVC pattern, we use struts to see how this new technology can help us quickly and easily create Web applications based on MVC.

Model-View-controller (Model-view-controller) mode

The MVC pattern was first presented in the programming language design of Smalltalk (an object-oriented language). Let's take a moment to ignore its history and focus on how it is applied in Web application development.

When Java's Servlets technology first appeared, programmers immediately realized that this was an extremely useful technique. Servlets is faster, more flexible, more reliable, and more powerful than the same era of CGI web development technology. However, there is a huge flaw in developing Web applications based on Servlets technology--you need to use statements such as OUT.PRINTLN to output browser-recognized HTML. The tendency to use this method frequently is a mistake, and development is a waste of time (programmers often have to quit all applications for recompilation). And it also makes it difficult to modify Web pages because the Web's performance and logic are mixed in a bunch of scary code.

As a workaround, JavaServer Pages (JSPs) appear and they turn servlets into the results of their operations. Using JSP technology, we express business logic in a series of <%> identities that are mixed in HTML. With the development of JSP as the core of the application although more than the core of the application of the servlet progress, but still seems to be messy, still need to use additional code to control the flow of application pages. On a JSP page full of formatting code, there is no place to add such additional control code. There is clearly a need to find another way.

It was not long before people realized that it was a good choice to apply JSP and servlets two of technologies to develop Web applications. After all, Servlets is good at handling business logic programming, processing requests, controlling the flow of functional pages, while JSP is the format of request processing results, user input through the browser. This working mechanism later became the Model2 that people say (using JSP or Servlets, a separate implementation of Web applications is called Model 1).

Model 2 is not a revolutionary new model, but it comes from the MVC pattern that appears in the Smalltalk language development process. In most cases, Java programmers tend to use these two nouns completely interchangeably.

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.