web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
 xmlns="http://java.sun.com/xml/ns/javaee"
 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">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
   <servlet-name>springMVC</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:config/spring-servlet.xml</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>   <!--表示启动容器时初始化Servlet-->
  </servlet>
  <servlet-mapping>
   <servlet-name>springMVC</servlet-name>
   <url-pattern>/</url-pattern>          <!-- 意思是拦截所有请求 -->
  </servlet-mapping>
</web-app>

spring-servlet.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 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
                    ">
    <bean name="/test/multi" class="com.mcm.web.controller.MultiController">
     <property name="methodNameResolver">
      <ref bean="paramMethodResolver"/>
     </property>
    </bean>
    <bean name="/test/helloworld" class="com.mcm.web.controller.HelloWorldController"></bean>
 
  <bean id="paramMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
  <property name="paramName" value="action"/>
    </bean>
 
 <!-- 配置视图解析器 -->
 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="prefix" value="/"/>
     <property name="suffix" value=".jsp"/>
 </bean>                  
 </beans>

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部分:

<body>

多个方法的Controller,本次方法是${method }

</body>

springMVC中一个controller多个方法的更多相关文章

  1. SpringMVC实现一个controller写多个方法

    MultiActionController与ParameterMethodNameResolver在一个Controller类中定义多个方法,并根据使用者的请求来执行当中的某个方法,相当于Struts ...

  2. SpringMVC实现一个controller里面有多个方法

    我们都知道,servlet代码一般来说只能在一个servlet中做判断去实现一个servlet响应多个请求, 但是springMVC的话还是比较方便的,主要有两种方式去实现一个controller里能 ...

  3. springMVC中一个class中的多个方法

    在前面.已经可以利用SpringMVC进行简单的例子了,但是,在controller中我们实现了Controller接口.这样就必须实现handleRequest(HttpServletRequest ...

  4. SpringMVC中的@Controller和@RequestMapping到底什么鬼?

    1.1 @Controller是什么 首先看个例子: @Controller @RequestMapping("/blog") public class BlogControlle ...

  5. SpringMVC中的Controller默认单例

    众所周知,Servlet是单例的. 在struts中,Action是多例的,每一个请求都会new出来一个action来处理. 在Spring中,Controller默认是单例的,多个请求都会访问同一个 ...

  6. (转)SpringMVC学习(七)——Controller类的方法返回值

    http://blog.csdn.net/yerenyuan_pku/article/details/72511844 本文所有案例代码的编写均建立在前文SpringMVC学习(六)——SpringM ...

  7. SpringMVC中对Controller使用AOP

    转自http://usherlight.iteye.com/blog/1306111 正确配置spring aop,在controller中使用AOP 在controller中使用AOP的问题主要在于 ...

  8. SpringMVC中重定向传参数的方法

    在spring的一个controller中要把参数传到页面,只要配置视图解析器,把参数添加到Model中,在页面用el表达式就可以取到.但是,这样使用的是forward方式,浏览器的地址栏是不变的,如 ...

  9. springmvc中的controller是单例的

    今天发现spring3中的controller默认是单例的,若是某个controller中有一个私有的变量a,所有请求到同一个controller时,使用的a变量是共用的,即若是某个请求中修改了这个变 ...

随机推荐

  1. 技术英文单词贴--N

    N normally 正常地,一般地

  2. php获取数据库中数据,转成json数据

    <?php //需要执行的SQL语句 //单条 $sql="select * from xinwen"; //多条数据 //$sql="select id,name ...

  3. redirect和forward

    1.重定向 <mvc:view-controller path="/" view-name="redirect:/admin/index"/>即如果 ...

  4. error: src refspec master does not match any. 错误处理办法

    自从上次学了git之后,很少用.今天在使用 本地仓库使用如下命令初始化: $ git init 之后使用如下命令添加远程库: $ git remote add origin git@github.co ...

  5. Office组件之Spire.XLS的DotNet操作

    Overview 在项目中,我们经常需要将程序中获得的大量数据导出到Excel表格中,打印报表:进一步,还可能生成其折线图,对数据的变化趋势进行分析,从而更好地开展项目工作. 最近,我发现了一个对于D ...

  6. python课程第三周重点记录

    1.关于set,set是一个无序且不重复的元素集合 s = set(["ss","dd","pp"]) #创建set s1 = set([& ...

  7. 我利用网上代码开发的JQuery图片插件

    我利用网上代码开发的JQuery图片插件 代码如下 (function($){ $.fn.FocusPic = function(options){ var defaults = { interval ...

  8. SQL联合更新(只要有关联字段就能执行更新!)

    update t1 set KCLX=t2.KCLX,KSFS=t2.KSFS from JX_PlannedCourse t1 inner join JX_Course t2 on t1.KCDM= ...

  9. hashcode深入理解

    带着问题去理解: 1. Object类HashCode方法是如何实现的,和String类有什么区别? 2.HashCode和Equals之间的关系? 一.hashCode作用 hashCode方法返回 ...

  10. C# 如何给sql数据库的日期字段插入空值

    在C#中声明日期变量时用SqlDateTime类型,引用:using System.Data.SqlTypes; 例子:user.AbortDate = SqlDateTime.Null;