1.在 web.xml 配置一个DispacherServlet
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.mvc</url-pattern>
</servlet-mapping>
2.在 WEB-INF 下 创建一个 [servlet-name]servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:is = "http://www.w3.org/2001/XMLSchema-instance"
is:schemaLocation =
"
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
"
>
<context:component-scan base-package="com.springmvc.*">
</context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
</beans>
3.在 handler 方法上 添加 注解
@RequestMapping(value="/login")
public String testHandler3(){
return "suc.jsp";
}