Today, a framework was built with SPRINGMVC to document the steps and configuration.
The JAR Packet network address is:http://yun.baidu.com/share/link?shareid=1109438387&uk=2836507213
Project Network address is: http://yun.baidu.com/share/link?shareid=3913316871&uk=2836507213
1. Need to import all the jar packages of the network tray
2. Modify the Web. xml file (add SPRINGMVC configuration)
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " xmlns=" Http://java.sun.com/xml/ns/javaee " xmlns:web=" http://java.sun.com/xml/ns/ Java ee " xsi:schemalocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ Web-app_2_5.xsd " version=" 2.5 "> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:config/springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</ Load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc< /servlet-name> <url-pattern>/</url-pattern> </ Servlet-mapping> </web-app>
3. Join the SPRINGMVC configuration file 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:context=" http://www.springframework.org/ Schema/context " xmlns:mvc=" Http://www.springframework.org/schema/mvc " xsi:schemalocation= " http://www.springframework.org/ schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/ schema/context/spring-context-3.2.xsd http:// Www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd "> <bean class= "Org.sprinGframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping "/> <bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <!-- Auto-Scan controller class --><context:component-scan base-package= " Com.xj.action "/> <!-- Define view resolver --><bean id=" Viewresolver " class=" Org.springframework.web.servlet.view.InternalResourceViewResolver "><property name=" Viewclass " Value= "Org.springframework.web.servlet.view.JstlView"/><property name= "prefix" value= "/"/> <property name= "suffix" value= ". JSP"/></bean><mvc:annotation-driven /><mvc :d efault-servlet-handler/> <mvc:resources mapping= "/asserts/**" location= "/asserts/"/> </beans>
4. Writing a controller file
@Controllerpublic class Hellocontroller {@RequestMapping (value= "/fruitlist") Public Modelandview HandleRequest ( HttpServletRequest request,httpservletresponse response) throws Exception {System.out.println ("Hello World"); return New Modelandview ("/hello");}}
And then start visiting http://localhost/TestSpringmvc/fruitlist always error, The reason is that the Modelandview introduced by the controller file above introduces the error to Org.springframework.web.portlet.ModelAndView, which should be introduced correctly. Org.springframework.web.servlet.ModelAndView
So far, SPRINGMVC's configuration is over.
This article is from the "Bulajunjun" blog, make sure to keep this source http://5148737.blog.51cto.com/5138737/1614763
SPRINGMVC Configuration Detailed