Javaweb (vi) MVC and three-tier architecture design

Source: Internet
Author: User

Objective

This is a time to learn Hadoop, but also want to review their web knowledge. So spend the rest of your time to take these web knowledge to a good consolidation! Nothing can stop me from moving forward.

First, let's look at:

C/S: client/server (FAT client)
b/S: Browser/server (thin client)
JavaBean: is a generic class (entity Bean) that contains three criteria: a parameterless construct, a private property, a public getter, and a setter method.

First, the Model1 of Javaweb development mode

In fact, in front of the javaweb knowledge we mainly talk about two major categories: one is servlet, two is JSP.
Servlet is to solve static page problem, can implement dynamic page , make maintenance, development more convenient, but also have shortcomings, embed HTML code in servlet is too troublesome , every time to out.println (); Output.
So there is JSP, the content of theJsp is HTML, for the convenience of writing HTML, writing pages, in essence, JSP is also a servlet, so in it will inevitably write some Java code, that is, scripts, In order not to make it so confusing, the tag is added, and the El expression is used as a substitute for the script.
But in writing some projects, it is still very troublesome, because the business logic code, the code that interacts with the database, the HTML code these categories, the style, the effect is completely different mixed together, the result is the code maintenance, readability and extensibility are very poor , such as to change a demand,
Then you have to read all the code, understand, or else you might have changed a piece of code, causing multiple errors elsewhere, and this design pattern is called pattern one (model 1).

    

Ii. javaweb Development Model MODEL2 (MVC) 2.1, overview

In order to improve the shortcomings mentioned above, that is to put the business logic code together, display the HTML code of the page together, and the database interaction code together , so that the development of ideas more clear, more convenient maintenance, this is called the MVC model .

M:model model, representing the business logic Code and database code , V:view to the data display code , such as JSP page, is dedicated to display data, beautify the page.

C:controller control,a servlet that acts as the role, connects the view and model, obtains instructions from the view, obtains the required data from the model through the business logic code, and then passes over the servlet to the view layer to display . The meaning of the MVC three layer structure!

The graph analysis is:

        

We open the browser, enter the URL, the request page to the server (JSP may be other), and then display to the browser , and then by clicking on the JSP page content, submit the request, to the server, also to the control (Servlet) this piece ,

Servlet through the analysis of the request, know what the user needs, data, then through the model, get the data from the database, in the JSP, the data displayed in the JSP sent back to the browser, displayed in the user to see,

So we often say that JSP is the view layer, to the user to see, servlet as a control process, and write operation database code, business logic code belongs to model. This is the application of MVC.

2.2. Analysis

JSP + Servlet + JavaBean
MVC: Development Patterns
M:model Model javabean| Four scopes
V:view View JSP
C:controller Controller Servlet

   

Third, classic three-tier architecture

The presentation layer (Web layer), the Business Logic Layer (service layer), the Data Access Layer (DAO layer), and a graph to describe the relationship:

    

Because now only learning servlet,jsp, so in the presentation layer is the servlet and Jsp , if you learn 3 large framework, struts, Hibernate, Spring, will find struts is a framework for processing the presentation layer, Hibernate is a framework in the DAO layer, and spring is the service layer.

    

Layered thinking: strong cohesion and weak coupling

The package naming structure in the actual project , which is also coded according to the three-tier architecture idea:

    

Analysis: (XXX: On behalf of the company name, YYY: On behalf of the project name)

Com.xxx.yyy.dao DAO layer Interface Com.xxx.yyy.dao.impl DAO Layer implements Com.xxx.yyy.service service layer interface com.xxx.yyy.se Rvice.impl Service Layer Implementation Com.xxx.yyy.web Web Layer com.xxx.yyy.util Toolkit com.xxx.yyy.domain java Bean

Iv. Summary

Classic three-tier architecture and MVC relationships:

They're two unrelated things, classic three-layer architecture is a layered thinking, the development model is divided into these three layers , each person according to their own expertise, the development of different modules, such as front-end engineers, then the special research presentation layer can, how to make the page more beautiful,

How to attract others, and some specialized in database work, you can only focus on the operation of the database, how to make the query faster and more effective, without having to pay attention to the data how to display this problem. This is the great benefit of layering.

And MVC is a design pattern that separates the HTML code from the business logic code, making the code look clearer and easier to develop .

If they have a relationship: they can only say they have a common point, layering, decoupling.

   

Javaweb (vi) MVC and three-tier architecture design

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.