SpringMVC框架搭建步骤:
1、将需要jar包导入lib文件夹下 2、配置web.xml 3、配置springMVC核心配置文件 4、编码Controller类
说明:本项目源码导入eclipse,在tomcat运行后 输入http://localhost:8080/BrainTrain/welcome.jsp进行测试
所需的jar包:http://pan.baidu.com/s/1i3QKYNF(百度云盘)
项目源码:http://pan.baidu.com/s/1kTWM9Rh;(百度云盘)
一、配置web.xml
BrainTrain
index.html
index.jsp
springMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:config/springAnnotation-servlet.xml
1
springMVC
/
二、配置springMVC核心配置文件:springAnnotation-servlet.xml
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.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-3.0.xsd">
三、编写Controller类
package com.chuck.codeResource.user;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
@Controller
@RequestMapping("/user")
public class LoginController extends MultiActionController {
@RequestMapping("/addUser")
public String addUser(HttpServletRequest request,HttpServletResponse response){
System.out.println("-----add----");
String result="this is addUser";
request.setAttribute("result",result);
return "/welcome";
}
@RequestMapping("/delUser")
public String delUser(HttpServletRequest request,HttpServletResponse response){
System.out.println("-----delUser----");
String result="this is delUser";
request.setAttribute("result",result);
return "/welcome" ;
}
@RequestMapping("/updateUser")
public String updateUser(HttpServletRequest request,HttpServletResponse response){
System.out.println("-----update----");
String result="this is updateUser";
request.setAttribute("result",result);
return "/welcome";
}
}
四、配置访问的jsp页面:welcome.jsp
pageEncoding="utf-8"%>
Insert title here本次执行的方法是:${result}