所需要的 jar 包下载地址:
https://download.csdn.net/download/qq_35318576/10275163
配置一:
新建 springmvc.xml 并编辑如下内容:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 8 http://www.springframework.org/schema/tx 9 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context-3.2.xsd 12 http://www.springframework.org/schema/mvc 13 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 14 15 <!-- 自动扫描的包名 --> 16 <context:component-scan base-package="com.jd.yw" /> 17 18 <!-- 默认的注解映射的支持,自动注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter --> 19 <mvc:annotation-driven /> 20 21 <!-- 视图解释类 --> 22 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 23 <property name="prefix" value="/WEB-INF/jsp/" /> 24 <property name="suffix" value=".jsp" /> 25 <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 26 </bean> 27 28 <!-- 对静态资源文件的访问 --> 29 <mvc:resources mapping="/images/**" location="/WEB-INF/images/" cache-period="31556926" /> 30 <mvc:resources mapping="/js/**" location="/WEB-INF/js/" cache-period="31556926" /> 31 <mvc:resources mapping="/css/**" location="/WEB-INF/css/" cache-period="31556926" /> 32 33 </beans>
配置二:
web.xml 文件配置 SpringMVC
1 <servlet> 2 <servlet-name>springMVC</servlet-name> 3 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 4 <init-param> 5 <param-name>contextConfigLocation</param-name> 6 <param-value>classpath:spring-mvc.xml</param-value> 7 </init-param> 8 <load-on-startup>1</load-on-startup> 9 </servlet> 10 <servlet-mapping> 11 <servlet-name>springMVC</servlet-name> 12 <url-pattern>/</url-pattern> 13 </servlet-mapping>
配置三:
新建 Controller 配置 @RequestMapping 便可以进行访问了