Spring3 MVC Configuration Detailed

Source: Internet
Author: User
Tags exception handling

Directory


First, the preface
Second, spring MVC core classes and interfaces
Spring MVC Core Flowchart

Iv. Spring MVC dispatcherservlet Description

V. Description of the spring MVC parent Context

Six, springmvc-mvc.xml configuration file fragment explanation
How spring MVC accesses static files, such as Jpg,js,css.

How the spring MVC request maps to a method in a specific action.

Interceptor in Spring MVC:
How the spring MVC uses interceptors.

Xi. How spring MVC implements global exception handling.

12. How spring MVC Logs global exceptions to the log.

13. How to do junit Unit test for action in Spring3 MVC.

14. Spring MVC forwarding and redirection

Spring MVC handles AJAX requests

16. Spring MVC Description of writing several configuration files

17. How spring MVC obtains spring-managed beans

18. Spring MVC Multi-View Controller

19, <mvc:annotation-driven/> Exactly what kind of work
20, this article Springmvc.xml configuration file is the core, here to a download address

Description: The author is the original author of the article, reproduced please specify the source: This article address: http://elf8848.iteye.com/blog/875830

Q-Q Group has a common exchange, welcome to join: 34292021

First, the foreword:

Hello, Spring3 mvc is a very good MVC framework, since it was released in version 3.0, and now more and more teams are choosing SPRING3 MVC. SPRING3 MVC structure is simple, should be the sentence: Simple is beautiful, and he is powerful without losing flexibility, performance is also excellent.

The official download URL is: http://www.springsource.org/download (this article uses the Spring 3.0.5 version)

Struts2 is also an excellent MVC architecture, with many advantages such as good structure. But here is the disadvantage, Struts2 because of the use of value stacks, OGNL expression, struts2 tag library, etc., will result in the application of performance degradation. STRUTS2 's multi-layer interceptor, multiple instance action performance is very good. You can refer to an article I wrote about spring MVC versus Struts2 versus servlet http://elf8848.iteye.com/admin/blogs/698217

Advantages of SPRING3 MVC:

1, Spring3 MVC Learning difficulty is less than struts2,struts2 use of redundant functions too much. Oh, of course, this is not a determining factor.

2, Spring3 MVC can easily write a good performance of the program, Struts2 to be careful to write a good performance of the program (refers to the MVC part)

3. The flexibility of SPRING3 MVC is beyond your imagination, and spring's extensibility is legendary, and Spring3 MVC will certainly not lag behind, and will not be limited by the use of the MVC framework.

STRUTS2 's many advantages: slightly ... (Oh, is not unfair.) )

Many articles at the beginning of the total to blow some cattle, to attract the reader's attention, the reader's appetite, so that everyone will be interested in the next look. This article is no exception. But make sure you don't regret it after you read it.

Reprint please indicate the source: This article address: http://elf8848.iteye.com/blog/875830

second, the core class and interface:

Let's take a look at several important interfaces and classes. Now do not know what they are do not matter, first mix face ripe, for later know they play a foundation.

Dispatcherservlet--Front Controller

Handlermapping interface--mapping for processing requests

Implementation classes for handlermapping interfaces:

simpleurlhandlermapping maps a URL to a controller through a configuration file

defaultannotationhandlermapping maps a URL to a controller class through annotations

Handleradapter interface--mapping for processing requests

Annotationmethodhandleradapter class, by annotations, maps a URL to a method of the Controller class

Controller Interface--controller

Because we use the @controller annotation, the class that adds the @controller annotation annotation can act as a controller (Action) responsibility,

So we didn't use this interface.

Handlerinterceptor Connector--Interceptor

Without graphs, we implement this interface ourselves to complete the work of the Interceptor.

Implementation classes for Viewresolver interfaces

The Urlbasedviewresolver class passes a configuration file to a view to handle

Internalresourceviewresolver class, more than the above class, has joined the JSTL support

View interface

Jstlview class

Localresolver interface

Handlerexceptionresolver interface--Exception handling

Simplemappingexceptionresolver Implementation Class

Modelandview class

No diagram.

third, the core flow chart

This picture is my personal drawing, there is not rigorous place, everybody deal with see. Better than nothing.

Reprint please indicate the source: This article address: http://elf8848.iteye.com/blog/875830


iv. Description of Dispatcherservlet

Using spring MVC, configuring Dispatcherservlet is the first step.

Dispatcherservlet is a servlet, so you can configure multiple dispatcherservlet.

Dispatcherservlet is the predecessor controller, configured in the Web.xml file. To intercept matching requests, the servlet intercept matching rules are defined by themselves, and the intercepted requests are distributed to the target controller (the action we write) according to certain rules.

"So-and-so": depending on which handlermapping interface you are using, the implementation class is different.

See first example: XML code    <web-app>       <servlet>           <servlet-name>example</servlet-name>           <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class>            <load-on-startup>1</load-on-startup>        </servlet>       <servlet-mapping>            <servlet-name

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.