SpringMVC快速搭建
一、导包
包含驱动包
二、核心配置文件
放在src目录下
SpringMVC.xml
建议开启注解模式,使用注解来配置controller
三、配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>springmvc</servlet-name> <!--DispatcherServlet前端控制器--> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:SpringMVC.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <!-- 能拦截所有的资源,包括jsp html js css等(不建议使用) *.action *.do 后缀名(可以使用) / 目录拦截,会放行静态资源(可以使用) --> <url-pattern>*.action</url-pattern> </servlet-mapping> </web-app>
四、创建controller
@Controller
public class Hello {
@RequestMapping(value = "/hello.action")
public void hello(){
System.out.println("hello springMVC");
}
}