Spring MVC 01 - Introduction to Spring MVC Framework

1. Before the spring mvc framework, the web application structure of java language was mainly implemented by Servlet technology or JSP technology

1.1 Servlet technology to realize Web application











The web application will have many servlets. The web application runs on the server. After the request from the browser arrives at the server, the server assigns the corresponding servlet to process the business, and outputs the page display content through the java code.

1.2 JSP technology to realize Web application


A web application will have many JSP pages. The web application runs on the server. After the request from the browser arrives at the server, the server assigns the corresponding JSP page to process business and displays the processing result in the JSP page.

1.3 Through the above description of servlet and Jsp applications, it can be seen that a single servlet can handle all transactions of a request, and the same is true for jsp. If it is a simple business, this is no problem; but everyone knows that building a website will involve a lot of complex logic and various display pages. If it is still handled with servlet or JSP technology, it will be very difficult.

2. Through the above description, we come to a conclusion that servlet and JSP are not suitable for complex website development mainly because they mix business logic with page display, which causes great inconvenience to development and maintenance. Spring mvc solves this problem well, spring mvc is divided into three parts:

M - Model refers to the data content requested by the browser, generally a POJO class that carries data

V - View refers to the UI part, as long as it is responsible for displaying the content returned by the server, it can be a jsp page, Velocity, Freemaker

C - Controller refers to the controller, which manages the entire application request. It calls the relevant service to generate a model according to the browser's request, and transmits the model to the corresponding view for display.

Let's take a look at a web application using the spring mvc framework:


front controller (dispatcher servlet), the front controller can be understood as the front desk staff of a company, the request initiated by the browser can be understood as the customer who comes to visit, the customer (browser request) comes to the company (server), the front desk staff (front controller) will First consult the purpose of the customer's visit, and provide corresponding services according to the customer's requirements. The front controller (front controller) consults the purpose and the process of giving a reply, which is Handler Mapping. Handler Mapping will process the code location of the url according to the requested url Return it to the front controller, and the front controller calls the relevant code according to the location specified by the Handler Mapping, and obtains the processing result. After the front controller gets the processing result, it needs to call the View Resolver to process the result display method. After the View Resolver informs the front controller of the display method, the front controller calls the corresponding View to display the result, and sends the final result to the browser

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326030954&siteId=291194637