(a) Introduction to Spring MVC

Source: Internet
Author: User
Tags map data structure object model

I. Overview

Both spring Web MVC and STRUTS2 are the framework of the presentation layer, which is part of the spring framework. Spring Web MVC is a Java-based lightweight web framework that implements a request-driven type of web MVC design pattern.

Even with the idea of the MVC architecture pattern, the Web layer is decoupled from responsibility, and the request-based driver is the use of the request-response model, and the purpose of the framework is to help us simplify development, and Spring MVC greatly simplifies our daily web development.

ii.Comparison of Struts2 and Springmvc
1. The SPRINGMVC entrance is a servlet, the front controller, and the STRUTS2 entry is a filter. 2, Springmvc is based on method development (a URL corresponding to a method), request parameters passed to the parameter of the method, can be designed as a single case or multiple examples (recommended singleton), Struts2 is based on class development, passing parameters are through the properties of the class, can only be designed as a number of examples. 3, struts uses the value stack to store the request and the response data, through the OGNL accesses the data, SPRINGMVC through the parameter parser is requests the request content parsing, and assigns the method parameter the value, the data and the view encapsulates the Modelandview object, Finally, the model data in Modelandview is transferred to the page via the request domain. The JSP view parser uses Jstl by default.

third, the advantages   
√ allows us to design a clean web layer and a thin web layer very simple, √ a more concise web layer development, √ natural integration with the spring framework (such as IOC container, AOP, etc.), √ provide a strong convention than the configuration of the contractual programming support; √ can easily conduct the web layer of unit testing; √ Support Flexible URL-to-page mapping; √ Easy integration with other view technologies such as velocity, freemarker, etc., because model data is not placed in a particular API, but in a model (map data structure is implemented so it is easily used by other frameworks) √ Very flexible data validation, formatting and data binding mechanism, can use any object for data binding, do not need to implement a specific framework of api;√ provide a set of powerful JSP tag library, simplify JSP development; √ Support flexible localization, subject resolution, √ simpler exception handling; √ support for static resources; √ Support restful style.
FourSpring MVC Architecture

1,  the user sends the request to the front controller Dispatcherservlet, the front controller receives the request and does not process itself, but invokes the processor mapper. 2  . Dispatcherservlet calls the Handlermapping processor mapper when the request is received. Handlermapping will map the request to the Handlerexecutionchain object (which contains a handler processor (page Controller) object, multiple Handlerinterceptor Interceptor) objects. 3  . The processor mapper locates the specific processor according to the request URL, and returns the Processor object and the processor interceptor (if any) to Dispatcherservlet. 4,  Dispatcherservlet through the Handleradapter processor adapter call Processor 5,  the execution processor (controller, also known as the back-end controller). Return execution results, encapsulated in Modelandview 6,  dispatcherservlet Modelandview to Viewreslover View parser, Viewresolver will parse the logical view name into a specific view, With this strategy mode, it is easy to replace other view technology;   7,  viewreslover after parsing, return to the specific view 8,  dispatcherservlet The view (the object model data is populated into the view). The model here is actually a map data structure, so it is easy to support other view technologies; 9.  

  

(a) Introduction to Spring MVC

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.