Brief introduction
Springmvc as a front end MVC framework of the rising star, with the previous Struts similar, but more flexible, simple to configure and Spring and the fiery RESTful combination of better.
Principle
corresponding to the above picture, combined Springmvc the source of the first from Web. XML speaking of. When the container starts, load Web. Xml. Whether it's a basic jsp and servlet Server, or a broader range of JBoss Support, you can support Springmvc .
1. the corresponding URL path is configured within Web. XML and the corresponding DISPATCHERSERVLet is requested .
2. after finding the Dispatcherservlet class? Execute the doservice method, after some judgment in the execution of the Dodispatch method, this method is used to sequence the central handmapping . If there is no corresponding controller in handmapping , the corresponding controller is called. can be
3. because spring-mvc is a method-level, if the returned string is converted to a View object; Modelandview You can return directly.
4.DispatcherServlet accept the data through Viewresolver To parse the rendering to the server side, the whole is such a process.
Simple configuration
Download address :http://repo.spring.io/libs-release-local/org/springframework /spring/
XMLConfiguration
Xml
Web. XML is a Sun Company for JSP application-specific, which means that for all JSP application of the metropolis this is generally the entrance of any frame, so no matter what kind of frame will be entered from this entrance
<servlet> <servlet-name>springMVC</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class> </servlet> < servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/*</ Url-pattern> </servlet-mapping>
Spring-servlet.xml
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc= "Http://www.springframework.org/schema/mvc" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xmlns: aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" Xsi:schema location= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans- 3.0.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/sche Ma/aop/spring-aop-3.0.xsd Http://www.springframework.org/schema/tx HTTP://WWW.SPRINGFRAMEWORK.ORG/SC Hema/tx/spring-tx-3.0.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring- Context-3.0.xsd "> <!--enables spring to auto-detect components such as the controller-to-<context:component-scan of annotations Base-package = "Com.minx.crm.web.controller"/> <bean name= "/test/helloworld" class= " Com.cfl.controller.HelloWorldController "></bean> <bean id=" Viewresolver "class=" Org.springframewor K.web.servlet.view.internalresourceviewresolver "p:prefix="/web-inf/jsp/"p:suffix=". JSP "/></bean S>
Controller
Package Com.cfl.controller;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.web.servlet.modelandview;import Org.springframework.web.servlet.mvc.controller;public class Helloworldcontroller implements controller{@ Overridepublic Modelandview handlerequest (httpservletrequest request,httpservletresponse response) throws Exception { TODO auto-generated Method StubSystem.out.println ("Helloword"); return new Modelandview ("Welcome");}}
In summary, compared to struts on the SPRINGMVC combination of annotations on the way to liberate the work of the program ape, in addition, and spring combined better, from the configuration controller up
It is the same as spring's habit. This is only a very entry-level description, more SPRINGMVC related to several major components are not deep, it is worth learning.
SPING-MVC (a) Summary of the principle of SPRING-MVC