项目文件布局:
web.xml文件:
< xml version="1.0" encoding="UTF-8" >
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
spring-servlet.xml文件:
< xml version="1.0" encoding="UTF-8" >
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-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
">
MultiController.java文件:
package com.mcm.web.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
public class MultiController extends MultiActionController {
public ModelAndView add(HttpServletRequest request,HttpServletResponse response){
System.out.println("------------add------------------");
return new ModelAndView("/aaa", "method", "add");
}
public ModelAndView update(HttpServletRequest request,HttpServletResponse response){
System.out.println("------------update------------------");
return new ModelAndView("/aaa", "method", "update");
}
}
aaa.jsp文件body部分:
多个方法的Controller,本次方法是${method }
多个方法的Controller,本次方法是${method }
多个方法的Controller,本次方法是${method }
多个方法的Controller,本次方法是${method }
多个方法的Controller,本次方法是${method }