Servlet notes-MVC development model and three-tier architecture

MVC development model

JSP evolution history

  1. In the early days, there was only Servlet and no JSP. In this way, only response can be used to output tag data. It is very painful to manually splice HTML and all data, as shown below
    Insert picture description here
  2. Later, SUN company launched jsp, developers can directly write dynamic java code in HTML pages to obtain data, which simplifies the development of Servlet (actually, the work of assembling data and html tags is handed over to jsp to do it automatically. The essence has not changed. The picture below shows the java file corresponding to jsp automatically generated in the work directory of tomcat when tomcat is running and when accessing the jsp page. Jsp is essentially a servlet)
    Insert picture description here
  3. But if the project volume is large, the system has HTML code and JAVA code, which is messy
  4. If JSP is used excessively, the project code will be confused, difficult to maintain, and difficult to divide and cooperate
  5. Later, JavaWeb development borrowed from the MVC development model, which made the program design more reasonable and easier to maintain.

MVC

It is a design idea used to solve system architecture problems.

  1. M: Model, model, responsible for completing specific business logic. Such as querying the database, encapsulating objects
  2. V: View, view, used to display data
  3. C: Controller, controller, does not participate in specific business, only distribution and process control

Divide the program into 3 parts, each of which performs its duties, reduces the coupling degree of the system, facilitates division of labor and collaboration, and project maintenance
Insert picture description here

In the primitive JavaWeb development, Servlet is regarded as Controller, JavaBean is regarded as Model, and JSP is regarded as View.

advantage
  1. Reduce system coupling , facilitate maintenance, and facilitate division of labor and collaboration
  2. High reusability
Disadvantage
  1. Not suitable for small and medium-sized applications
  2. Increased the complexity of the system architecture, and high requirements for developers

Now that the MVC development model is adopted, JSP is only used for view display, and no Java code is written in JSP, then how to transfer the data to the JSP page => use EL expressions and JSTL tags

Three-tier architecture

Is a software design architecture (note that it is distinguished from the MVC development model)

  1. Interface layer (presentation layer): the interface that the user sees, and the user can interact with the server through the components on the page
  2. Business logic layer: processing business logic
  3. Data access layer: Operational data storage

In fact, the three-tier architecture is generally in the back-end development, and only reflects two layers. In the project, the core business classes will be placed on one layer, such as under the service package, and the classes responsible for persistence layer operations will be placed on one. Layer, such as placed under the dao package or repository package. Each layer follows the principle of single responsibility and maintains loose coupling between layers. Each module keeps as little attention as possible to the outside world. For example, the dao layer only provides pure database CRUD operations. The dao only cares about the DB, only the data addition, deletion, modification, and query, and does not care about any business logic; the service layer only cares about the business logic, and does not care about the details of the data processing by the dao layer.

Insert picture description here

Guess you like

Origin blog.csdn.net/vcj1009784814/article/details/106084674