Build the spring MVC process
Directory structure:
Process is as follows
1 jar packages that need to be imported with SPRINGMVC
2 in Web.xml need to add the following configuration
<servlet>
<servlet-name>golfing</servlet-name>
<servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class>
<load-on-startup>1</ load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>golfing</ servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3 config file under Web-inf
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Mvc=http://www.springframework.org/schema/mvc xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns: context= "Http://www.springframework.org/schema/context" xsi:schemalocation= "http://www.springframework.org/s Chema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework. ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.O Rg/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <mvc:annotat Ion-driven/> <context:component-scan base-package= "Com.sm.nothing.controller"/> <!--configuration View Parser
; <bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "Viewcla" SS "Value=" Org.springframework.web.sErvlet.view.JstlView "/> <property name= prefix" value= "/web-inf/views/" ></property> <PR
Operty name= "suffix" value= ". jsp" ></property> </bean> <!--...--> </beans>
It turns out that completely <mvc:annotation-driven/> can get rid of
4 controller classes are as follows:
Package Com.sm.nothing.controller;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.servlet.ModelAndView;
@Controller public
class hellocontroller{
@RequestMapping (value= "/index.html") public
Modelandview Index () {
Modelandview Mav = new Modelandview ("Index", "MSG", "Springmvc, Hello world!");
return Mav
}
}
the contents of web-inf/views/index.jsp in the 5 directory are:
<p>${msg}</p>
6 Execution Effect
Home map
Input path http://localhost:8080/springmvctest/index.html, page success jump
Download the address for the executable source code below
Http://www.kuaipan.cn/file/id_140422426734362790.htm