SpringMVC Working Principle

Source: Internet
Author: User


SpringMVC framework Introduction

1) Spring MVC is a follow-up product of SpringFrameWork and has been integrated into Spring Web Flow. The Spring framework provides a full-featured MVC module for Building Web applications. Using Spring-pluggable MVC Architecture, you can choose whether to use a built-in Spring Web framework or a Web framework such as Struts. Through the policy interface, the Spring framework is highly configurable and contains multiple view technologies, such as assumerver PagesJSP, Velocity, Tiles, iText, and POI. The Spring MVC Framework does not know the view used, so it does not force you to only use JSP technology.

Spring MVC separates the roles of controllers, model objects, schedulers, and processing program objects, making them easier to customize.

2) Spring MVC framework consists of DispatcherServlet, processor ing, processor (Controller), view parser, and view.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1445006215-0.jpg "title =" 1353059506_5137.jpg "alt =" 135749995.jpg"/>

SpringMVC Interface Description

DispatcherServlet interface:

Spring provides a front-end controller that distributes all requests in a unified manner. Before DispatcherServlet distributes requests to the Spring Controller, it is necessary to use the HandlerMapping provided by Spring to locate the specific Controller.

HandlerMapping interface: maps customer requests to the Controller.

Controller Interface:

The preceding request must be processed for concurrent users. Therefore, when implementing the Controller Interface, thread security must be ensured and reusable.

The Controller processes user requests, which is consistent with the role played by Struts Action. Once the Controller processes the user request, it returns the ModelAndView object to the DispatcherServlet front-end Controller. ModelAndView contains the Model and View ).

From a macro perspective, DispatcherServlet is the Controller of the entire Web application; from a micro perspective, Controller is the Controller in the Process of processing a single Http request, and ModelAndView is the Model returned in the Http request process) and View ).

ViewResolver interface:

View parser ViewResolver provided by Spring) searches for View objects in Web applications and renders the results to customers.

SpringMVC running principle

1. Submit the client request to DispatcherServlet

2. The DispatcherServlet Controller queries one or more HandlerMapping and finds the Controller that processes the request.

3. The DispatcherServlet submits the request to the Controller.

4. After the Controller calls business logic processing, it returns ModelAndView

5. The DispatcherServlet queries one or more ViewResoler view Resolvers and finds the view specified by ModelAndView.

6. The view is responsible for displaying the results to the client.

DispatcherServlet is the core of Spring MVC. It is responsible for receiving HTTP requests and organizing and coordinating various components of Spring MVC. Its main tasks include:

1. Intercept URL requests in a specific format.

2. initialize the WebApplicationContext corresponding to the DispatcherServlet context and associate it with the WebApplicationContext at the business layer and persistence layer.

3. initialize components of Spring MVC and assemble them into DispatcherServlet.


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.