danjiezaiwoxin
丹为自己活得精彩
2016-07-09 10:10

SpringMVC一直报404,访问不到请求的action,求各位大神帮帮忙看看

<?xml version="1.0" encoding="UTF-8"?>

SpringMVC2

index.html
index.htm
index.jsp
default.html
default.htm
default.jsp


SpringMVC
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath*:config/SpringMVC-servlet.xml

1


SpringMVC
/


<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> 

<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>   

<bean  name="/test1/multi" class="com.tag.web.controller.MultiController">
     <property name="methodNameResolver">
          <ref  bean="ParamMethodResolver"/>
     </property>
</bean>       

<bean id="ParamMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
    <property name="paramName"  value="action"></property>
</bean>


<bean id="viewResolver"   class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="prefix" value="/"></property>
     <property name="suffix" value=".jsp"></property>
</bean>


```package com.tag.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("/multi","method","add");
}

public  ModelAndView  update(HttpServletRequest request,HttpServletResponse response){
    System.out.println("=====update======");
    return new ModelAndView("/multi","method","update");
}

}

访问的时候请求的是这个地址:http://localhost:8080/SpringMVC2/test1/multi?action=add




  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答