Spring mvc Process Overview, springmvc Process Overview

Source: Internet
Author: User

Spring mvc Process Overview, springmvc Process Overview

Most Java applications are Web applications, and the presentation layer is an important part of Web applications. Spring provides an excellent Web framework-Spring MVC for the presentation layer. Like many other Web frameworks, it is based on the MVC design concept. In addition, it adopts a loosely coupled pluggable component structure, which is more scalable and flexible than other MVC frameworks.
Spring MVC uses a set of MVC annotations to make POJO the Controller that processes requests without any interface. Spring MVC also supports REST-style URL requests: annotation-driven and REST-style Spring MVC is one of Spring3.0's most brilliant features. In addition, Sping MVC performs well in data binding, view parsing, localization, and static resource processing. It surpassed Struts, WebWork and other MVC frameworks in terms of framework design, scalability, and flexibility, and jumped from the original chaser to become the leader of MVC.
The Spring MVC framework is centered around the DispatcherServlet core. DispatcherServlet is the director and general plan of Sprrng MVC. It intercepts requests and distributes them to corresponding processors for processing. The Spring MVC Framework includes annotation-driven controllers, request and response information processing, view parsing, localization parsing, file uploading parsing, exception handling, and form tag binding.
Spring MVC processing process
From receiving requests to returning responses, many components of Spring MVC framework work together and perform their respective duties in an orderly manner. In the entire framework, DispatcherServlet is at the core. It is responsible for coordinating and organizing different components to complete request processing and returning responses. Like most Web MVC frameworks, SpringMVC receives all requests through a front-end Servlet and delegates specific work to other components for processing. DispatcherServlet is the front-end Servlet of Spring MVC.
1. the whole process starts when the client sends an HTTP request, and the Web application server receives the request. If the request ing path matches the DispatcherServlet (in the web. in xml), the Web Container transfers the request to DispatcherServlet for processing.
2. after the DispatcherServlet receives the request, it will be based on the request information (including URL, HTTP method, request message header, request parameters, Cookie, etc) and HandlerMapping configuration to find the processing Handler for the request ). HandlerMapping can be regarded as a routing controller and Handler as the target host. It is worth noting that Spring MVC does not define a Handler interface. In fact, any Object can become a request processor.
3. After DispatcherServlet obtains the Handler corresponding to the current request according to HandlerMapping, it encapsulates the Handler through the HandlerAdapter and calls the Handler through a unified adapter interface. HandlerAdapter is a framework-level interface of Spring MVC. As its name suggests, HandlerAdapter is an adapter that calls various Handler methods using a unified interface.
4. After processing the business logic, the processor will return a ModelAndView to DispatcherServlet. ModelAndView contains the view logic name and model data information.
5. ModelAndView contains the "logical view name" rather than the real view object. DispatcherServlet parses the logical view name to the real view object through ViewResolver.
6. After obtaining the View object View, DispatcherServlet uses this View object to render the model data in ModelAndView.
7. the Response Message received by the client may be a common HTML page, an XML or JSON string, or even an image or a PDF file.

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.