Javaweb three frames and MVC design Patterns

Source: Internet
Author: User

Javaweb three frames and MVC design Patterns

Reproduced, please see the original 50890705

First, the concept of MVC design pattern 1.MVC

First we need to know that the MVC pattern is not unique to the Javaweb project, MVC is a software architecture model in software engineering that divides software systems into three basic parts: model, view, and controller, which is MVC. It is a model of software design, the first proposed for Trygve Reenskaug, for the Xerox Palo Alto Research Center (Xerox PARC) Smalltalk language invented a software design model.

2.MVC explanation

Although MVC is not unique in Java, but now almost all of the B/S architecture has adopted the MVC framework model, but MVC in the B/s architecture is not fully implemented, in fact, we do not need to master the unfinished part.
Controller controllers: The controller is the processing logic of the control request, processing the request, responsible for forwarding the request;
• Views View: The view is the interface that the user sees and interacts with, such as HTML (static resources), JSP (dynamic Resource), and so on.
• Model: The model represents an enterprise specification, which is the processing of business processes/statuses and rules of business. The processing of business processes is opaque to other tiers, the model accepts requests for view data, and returns the final processing results. The design of the business model can be said to be the core of MVC.

Where 3.MVC mode comes in

The MVC pattern is widely used in various frameworks of Java, such as Struts2, Spring MVC, and so on.

STRUTS2 is a lightweight Web application framework based on MVC. Based on MVC, it is explained that Web applications based on Struts2 are naturally able to implement MVC, and that Struts2 focus on the various parts of MVC to help us with our development.

Second, Javaweb Classic three-layer architecture 1.Javaweb has undergone three periods

①jsp Model1 First generation
JSP Model1 is the early model of Javaweb, it is suitable for small web projects, low development cost! Model1 first generation period, the server side only JSP pages, all operations are in the JSP page, even the API to access the database is also done in the JSP page. That is to say, all things are coupled together and are extremely detrimental to later maintenance and expansion.

②jsp Model1 Second generation
JSP Model1 second generation has improved, the content of business logic into the JavaBean, and JSP page is responsible for display and request scheduling work. Although the second generation better than the first generation, but also let JSP do too much work, JSP in the view work and request scheduling (Controller) work coupled together.

③jsp Model2
JSP Model2 mode has been able to clearly see the full structure of MVC.
· JSP: The view layer, used to deal with users. Responsible for receiving the data used and displaying the data to the user;
· Servlet: The control layer, is responsible for finding the appropriate model object to handle the business logic, forwarded to the appropriate view;
JavaBean: The model layer, complete the specific business work, such as: open, transfer and so on.

This is the Javaweb experience of the three years, JSP Model2 suitable for many people to cooperate in the development of large-scale web projects, their duties, non-interference, conducive to the development of division of labor, conducive to the reuse of components. However, the development of Web projects is more difficult, and the technical requirements of developers are also improved.

2.JAVAWEB Classic three-layer frame

We often say that the three-layer framework is proposed by Javaweb, which means that this is javaweb unique!
The so-called three tiers are the presentation layer (the Web layer), the business logic layer, and the data access layer.
· Web layer: Contains Web-related content such as JSP and servlet;
• Business layer: The business layer does not contain the Javaweb API, it only cares about the business logic;
• Data layer: Encapsulates the access details of the database;

Note that the Javaweb API cannot appear in the business layer, such as request, response, and so on. In other words, the business layer code is reusable and can even be applied to non-web environments. Each method of the business layer can be understood as a panacea, such as a transfer business method. The business layer relies on the data tier, and the Web tier relies on the business layer!

Note: Many people on the internet are talking about whether MVC is a framework or a design pattern (the Baidu encyclopedia forcefully interprets it as a framework rather than a design pattern), although there is no MVC in the 23 design patterns in Java, I don't think it's much of a problem to discuss it. We can think of him as a thought, and all we need to do is to understand it, to apply it, to master the ideas, that's what we need to do.

Javaweb three frames and MVC design Patterns

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.