To use sping MVC, you only need to configure a Dispatcherservlet in Web. xml:
1 <servlet>2 <Servlet-name>Dispatcherservlet</Servlet-name>3 <Servlet-class>4 Org.springframework.web.servlet.DispatcherServlet5 </Servlet-class>6 </servlet>7 <servlet-mapping>8 <Servlet-name>Dispatcherservlet</Servlet-name>9 <Url-pattern>/*</Url-pattern>Ten </servlet-mapping>
Define a Dispatcherservlet-servlet.xml configuration file again:
1 <Beans>2 <!--Define Mapping -3 <BeanID= "UrlMapping"class= "Org.springframework.web.servlet.handler.simpleurlhandler-mapping">4 < Propertyname= "Mappings">5 <Props>6 <propKey= "demo.html">Demo</prop>7 </Props>8 </ Property>9 < Propertyname= "Interceptors">Ten <List> One <refBean= "Interceptor" /> A </List> - </ Property> - </Bean> the <BeanID= "Interceptor"class= "Org.springframework.web.servlet.theme.ThemeChangeInterceptor"/> - <!--Define View - - <BeanID= "Viewresolver"class= "Org.springframework.web.servlet.view.internalresource-viewresolver"> - < Propertyname= "Viewclass"> + <value>Org.springframework.web.servlet.view.internalresource-view</value> - </ Property> + </Bean> A <!--Define Control - at <BeanID= "Demo"class= "Com.yb.mvc.demo"> - < Propertyname= "ViewPage"> - <value>/demo.html</Valus> - </ Property> - </Bean> - </Beans>
Such a simple spring MVC-based application is created.
The use of spring MVC is simple, as shown in the code above, as long as we extend a path mapping relationship, define a view parser, and in defining a process plan for a business logic, Spring MVC can help us do all of the MVC functions.
Dispatcherservlet class-related structure diagram:
The Dispatcherservlet class inherits the HttpServlet and Dispatcherservlet performs the initialization of Spring MVC when the Servlet's Init method is called. Dispatcherservlet initializes what can be known in its Initstrategies method:
The overall design of Spring MVC