第一步导入jar包:我这里是导入3.05这个版本有点低够用进行
第二部 配置web.xml文件:
省去红色中要写入自动加载
配置spring
在WEB-INF下新建config文件 新建applicationContext.xml文件
第二步:我用的eclipse 这里命名 test 这里就需要在WEB-INF建一个test-servlet.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 启用spring mvc 注解 -->
<context:annotation-config />
<context:component-scan base-package="com.controller"></context:component-scan>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 请求映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/page/" p:suffix=".jsp">
</bean>
</beans>
第三步中java类中加入标签
package com.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/brt")
public class IndexController {
@RequestMapping(value="/login",method = RequestMethod.GET)
public String goIndex(){
System.out.println("进入");
return "index";
}
}
第四步
启动tomcat 后输入
http://localhost:8080/test/brt/login 简单配置springMVC