1. Create a new Java Web project
2. Import Jar Package
3, build a hello.jsp page under Web-inf.
1<%@ Page Language="Java"Import="Java.util.*"Pageencoding="Iso-8859-1"%>23<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en">4<Html>5<Head>6<Title>my JSP ' hello.jsp ' starting Page</title> 7 </head> 8 9 < Body>10 hello Springmvc11 </body< Span style= "COLOR: #0000ff" >>12 </html>
4. Configure the Web. xml file
1<?XML version= "1.0" encoding= "UTF-8"?>2<Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"Id= "webapp_id"Version= "3.0">34<Servlet>5<Servlet-name>dispatcherservlet</Servlet-name>6<Servlet-class>org.springframework.web.servlet.dispatcherservlet</Servlet-class>7<Init-param>8<Param-name>contextconfiglocation</Param-name>9<Param-value>classpath:spring-mvc.xml</Param-value>10</Init-param>11<Load-on-startup>1</Load-on-startup>12</Servlet>1314<Servlet-mapping>15<Servlet-name>dispatcherservlet</Servlet-name>16<Url-pattern>/</Url-pattern>17</servlet-mapping >18 19 <welcome-file-list>20 <welcome-file>index.jsp</welcome-file>21 </welcome-file-list>22 </web-app>
5. Configuring the Spring-mvc.xml File
1<?XML version= "1.0" encoding= "UTF-8"?>2<Beansxmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4Xmlns:context= "Http://www.springframework.org/schema/context"5Xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd6Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd ">78<Context:component-scanBase-package= "Com.proc"></Context:component-scan>910<BeanClass= "Org.springframework.web.servlet.view.InternalResourceViewResolver">11<Propertyname= "prefix" Value= "/web-inf/" />12 <property name = "suffix" Value= ". JSP" Span style= "COLOR: #0000ff" >></property>13 </bean>14 </ Beans>
Internalresourceviewresolver: View parser. File resource found based on URL address
Prefix: Prefix
Suffix: suffix
6. Configuring the Controller
1PackageCom.proc;23ImportOrg.springframework.stereotype.Controller;4Importorg.springframework.web.bind.annotation.RequestMapping;5 6 @Controller 7 Public class Hello { 8 9 @RequestMapping ("/hello")
public
String Hello () {System.out.println ("Hello Springmvc"); return "Hello";
+}
@RequetMapping annotation function is URL mapping
Test access
Spring MVC Primer Example (1)