Spring MVC General overview

Source: Internet
Author: User

1. Configure Web. XML to start SPRINGMVC
<!--start Spring mvc-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--If you do not configure the following: Spring MVC configuration files are placed by default in web-inf/[springmvc-name]-servlet.xml-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<!--troubleshoot post submissions garbled--
<filter>
<filter-name>characterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>characterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

2, the XML----------------is obsolete "not recommended use"
1), configure handlermapping, request map to Controller
<bean class= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" ></bean>

2), configuration Handleradapter, support multi-type processor
<bean class= "Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" ></bean>
See more:/org/springframework/web/servlet/dispatcherservlet.properties file pieces

4, the implementation of the Controller
Implements the Controller class and its subclasses. Implement the appropriate method.

5. Contextual relationship (Spring-spring MVC)
Spring MVC inherits the spring context.
View: Dispacherservlet The Initservletbean method of the parent class Frameworkservlet.

6, Annotation Way
1), configure handlermapping, request map to Controller
<bean class= "Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" ></bean >
2), configuration Handleradapter, support multi-type processor
<bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" ></bean>
See more:/org/springframework/web/servlet/dispatcherservlet.properties file pieces
7. Define the View parser
<!--View Resolver--
<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "Viewclass" value= "Org.springframework.web.servlet.view.JstlView" ></property>
<property name= "prefix" value= "/view/" ></property>
<property name= "suffix" value= ". JSP" ></property>
</bean>

Spring MVC General overview

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.