This article summarizes the basic configuration of spring MVC by first pasting a directory of my projects, with some extra files that you don't have to care about:
Some of the jar bags used in this:<a>http://download.csdn.net/detail/u012116457/8426199</a>
Next is the configuration of Web. XML:
<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "3.0" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "> <welcome-file-list> <welcome-file>index.jsp</ Welcome-file> </welcome-file-list> <!--1. Configure the Spring distributor (the URL that is blocked by the total control center will converge to the servlet)--><servlet> ; <servlet-name>springmvc</servlet-name> <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class> <!--Configure the spring context (load spring from this directory MVC configuration file)-<init-param> <param-name>contextConfigLocation</param-name> <param-va Lue>/web-inf/classes/spring/spring*.xml</param-value> </init-param> <load-on-startup>1</ Load-on-startup> <!--tomcat loads--></servlet><!--2 immediately after booting. Configure the URL template for spring interception to end with a. Do Url--> <servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>*.do</ url-pattern></servlet-mapping><!--3. Register the profile reader and listen for changes to the spring configuration file see note 3--><listener> <listener-class> Org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!--4. Sets the configuration file list to set the parameter configuration information for global parameter 3--><context-param><param-name>contextconfiglocation</param-name> <param-value>/WEB-INF/classes/spring/*Config.xml</param-value></context-param> <!--5. The coded character set is unified to UTF-8 (filter)--><filter><display-name>encodingfilter</display-name><filter-name >encodingFilter</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> </web-app>
Next is Springmvc-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:p= "http://www.springframework.org/schema/p" xmlns:mvc= " Http://www.springframework.org/schema/mvc "xmlns:context=" Http://www.springframework.org/schema/context "xmlns: Util= "Http://www.springframework.org/schema/util" xsi:schemalocation= "http://www.springframework.org/schema/ Beans Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd Http://www.springframework.org/schem A/context http://www.springframework.org/schema/context/spring-context-3.0.xsd Http://www.springframework . ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd Http://www.springframewo Rk.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd "> <!--@ For a detailed explanation of the use of the controller annotations, see (note. txt 1.) -<mvc:annotation-driven/> <!--<contExt:annotation-config/>-<!--scan all classes in the module package to complete bean creation and automatic dependency injection-<context:component-scan Base-package= "module" > </context:component-scan> <!--start the annotation feature of spring MVC to complete the mapping of request and annotation Pojo--><beancl ass= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <!--define the view parser, Adding prefix suffixes around the view model temporarily supports only JSP suffixes---<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" ><property name= "prefix" value= "/web-inf/views/"/><!--path prefix--><property name= "suffix" value= ". JSP "/><!--suffix--></bean></beans>
These are the most basic configurations of spring MVC, and here is an example of a control class:
Package Module.controller;import Javax.servlet.http.httpservletrequest;import Org.springframework.stereotype.controller;import org.springframework.web.bind.annotation.requestmapping;@ Controller@requestmapping ("/start") public class Startcontroller {private static String start= "Module/jsp/start" ; @RequestMapping ("/index.do") public String Start (HttpServletRequest request) {return start;}}
This is entered in the browser: Http://localhost:8080/springMVC/start/index.do can access to the start.jsp page
Play Spring MVC (iii)----Spring BASIC configuration file