This article summarizes the basic configuration of spring MVC by first pasting a screenshot of my project's catalog, 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)--<servle T> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.
Dispatcherservlet</servlet-class> <!--Configure Spring context (load Spring MVC configuration file from this directory)--<init-param> <param-name>contextConfigLocation</param-name> <param-value>/web-inf/classes/spring/sprin G*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <!--Tomcat Loads immediately after loading-</servlet> <!--2. Configure the URL template for spring interception to end with. 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.cont Extloaderlistener</listener-class> </listener> <!--4. Set profile list setting parameter with global parameter 3 configuration information-<context-param> <param-name>contextConfigLocation</param-name> & Lt;param-value>/web-inf/classes/spring/*config.xml</param-value> </context-param> <!--5. Coded character set for 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/sche Ma/context http://www.springframework.org/schema/context/spring-context-3.0.xsd Http://www.springframewor K.ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd Http://www.springframe Work.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:compon Ent-scan base-package= "module" > </context:component-scan> <!--start the Spring MVC Annotation feature to complete the mapping of request and annotation Pojo--&G
T <bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <!--definition view parser, adding prefix suffixes before and after the view model is temporarily supported only for 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> </b Eans>
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