Thinking about the Web three-tier architecture

Source: Internet
Author: User

1.MVC Design Ideas

The concept of MVC program design is a popular model of web development, in whichM (model) is modeled as JavaBean, which is used to encapsulate and store data; V (view) is a view, which is a JSP, which is used to display content; C (Controller) The servlet, which is used to process business logic . The general process is this: write a JSP page to obtain information (such as the login page to get the user login, password), and encapsulate the information into JavaBean, submitted to the server driven by Web container to encapsulate the data as request requests, to the servlet processing. The servlet obtains the user information from the request into the database query, returns the corresponding result (login success or failure), and then encapsulates the result into a response response to the client browser, which is displayed according to the response header and other information.



The MVC design idea separates the data encapsulation, the display and the business processing, the JavaBean, the JSP and the servlet all do their own best thing, the modularization makes the whole process clearer, conforms to the Java low-coupling idea, improves the code flexibility, is easy to expand and maintains. Specific division of labor such as:


2.WEB three-tier architecture

It can be seen from the data access layer that JavaBean both the data content and the data content, which violates the principle of single responsibility. We hope that JavaBean is simply used to encapsulate the data and others to do it, so in web development, the data access layer is further refined, JavaBean to encapsulate the data, and the data is persisted in the database (also can be XML files), through the DAO (data Access object) data Access objects to query the database (or parse XML files, etc.). Sometimes the view layer is not necessarily JSP-only, and some content needs to be displayed through servlet technology, such as a verification code for the login page. When the business logic is too large, the business logic layer will appear particularly bloated, not conducive to the expansion and maintenance, when the business functions can be abstracted into an interface, the specific functions of the subclass implementation. So the question comes, how do you know which class to deal with which business logic? The solution is to define a core servlet that receives all client requests and passes the request to the corresponding business processing subclass to handle it. Here you can see the implementation principle of Struts2, which is not mentioned here. In this way, the business logic layer is divided into two parts: the servlet for display and the servlet that distributes the business. Such as:



3 . Real Case

However, in real development, the above is not the ultimate solution. Take a practical case, develop a simple business-to-consumer electronic trading platform System (features include: User login, registration, email verification, view products, add goods, shopping cart, order, online payment, etc.), the package structure is as follows:


~ ~ to Be Continued ~ ~

Above are personal views, if in doubt, Welcome to Exchange ~ ~


Thinking about the Web three-tier architecture

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.