9
回答
Spring mvc 映射 到 方法,进不了控制器层
注册华为云得mate10,2.9折抢先购!>>>   

@小杨阿哥哥 你好,想跟你请教个问题:

2013-2-28 18:16:03 org.apache.catalina.core.StandardWrapperValve invoke
信息: [org.springframework.web.servlet.PageNotFound]No matching handler method found for servlet request: path '/login/login.action', method 'POST', parameters map['securityCode' -> array<String>['1764'], 'identityVerifyFlag' -> array<String>['0'], 'ipAddr' -> array<String>[''], 'gotoUrl' -> array<String>[''], 'macCode' -> array<String>[''], 'password' -> array<String>['admin'], 'user' -> array<String>['admin']]

 

请赐教,谢谢

举报
共有9个答案 最后回答: 3年前

你的spring-mvc配置文件是咋配的,我的后来改好了。

<mvc:annotation-driven>
	</mvc:annotation-driven>
	<context:component-scan base-package="com.xx.project"></context:component-scan>

	<mvc:resources location="/resources/*" mapping="/resources/**" />
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/*.do" />
			<bean class="com.xx.project.actions.UserLoginInterceptor">
			</bean>
		</mvc:interceptor>
	</mvc:interceptors>

	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

		<property name="messageConverters">
			<list>
				<bean
					class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/html;charset=UTF-8</value>
						</list>
					</property>
				</bean>
			</list>
		</property>
	</bean>
	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

	</bean>
	<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"
		p:viewClass="org.springframework.web.servlet.view.InternalResourceView" />

	<!-- 上传拦截,如最大上传值及最小上传值 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
		p:defaultEncoding="utf-8">
		<!-- one of the properties available; the maximum file size in bytes -->
		<property name="maxUploadSize" value="2000000" />
	</bean>

	<mvc:default-servlet-handler />

--- 共有 1 条评论 ---
萍水相逢_JAVA我的配置文件内容如下面的内容,请给予指导 5年前 回复
1、spring-mvc配置文件: 
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 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"> 


<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 --> 
<context:component-scan base-package="sy.controller,com.ailk" /> 


<!-- 避免IE执行AJAX时,返回JSON出现下载文件 --> 
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes"> 
<list> 
<value>text/html;charset=UTF-8</value> 
</list> 
</property> 
</bean> 
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> 
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters"> 
<list> 
<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 --> 
</list> 
</property> 
</bean> 


<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --> 
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/" p:suffix=".jsp" /> 


<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding"> 
<value>UTF-8</value> 
</property> 
<property name="maxUploadSize"> 
<value>32505856</value><!-- 上传文件大小限制为31M,31*1024*1024 --> 
</property> 
<property name="maxInMemorySize"> 
<value>4096</value> 
</property> 
</bean> 
<!-- 拦截器 --> 
<mvc:interceptors> 
<mvc:interceptor> 
<mvc:mapping path="/**" /> 
<bean class="sy.interceptors.SessionInterceptor"> 
<!-- 不需要session验证的地址 --> 
<property name="excludeUrls"> 
<list> 
<value>/menuController/allTreeNode.action</value> 
<value>/userController/reg.action</value> 
<value>/userController/combogrid.action</value> 
<value>/userController/combobox.action</value> 
<value>/userController/login.action</value> 
<value>/repairController/repair.action</value> 
<value>/repairController/delAndRepair.action</value> 
<value>/onlineController/datagrid.action</value> 
<value>/userController/logout.action</value> 
<value>/druidController/druid.action</value> 
<value>/login/login.action</value> 
</list> 
</property> 
</bean> 
</mvc:interceptor> 


<mvc:interceptor> 
<mvc:mapping path="/**" /> 
<bean class="sy.interceptors.SecurityInterceptor"> 
<!-- 不需要权限验证的地址 --> 
<property name="excludeUrls"> 
<list> 
<value>/menuController/allTreeNode.action</value> 
<value>/userController/reg.action</value> 
<value>/userController/combogrid.action</value> 
<value>/userController/combobox.action</value> 
<value>/userController/login.action</value> 
<value>/repairController/repair.action</value> 
<value>/repairController/delAndRepair.action</value> 
<value>/onlineController/datagrid.action</value> 
<value>/userController/logout.action</value> 
<value>/druidController/druid.action</value> 

<value>/bugController/showNote</value> 
<value>/bugController/bugglEdit.action</value> 
<value>/roleController/combogrid.action</value> 
<value>/userController/userInfo.action</value> 
<value>/resourceController/allTreeNode.action</value> 
<value>/userController/modifyCurrentUserPwd.action</value> 
<value>/login/login.action</value> 
</list> 
</property> 
</bean> 
</mvc:interceptor> 
</mvc:interceptors> 
</beans> 
2、login.jsp: 
<form id="loginForm" action="${pageContext.request.contextPath}/login/login.action" method="post"> 
<div class="mhlogin_img"></div> 
3、LoginController.java : 
package com.ailk.sso.web; 
import java.util.*; 
import javax.servlet.http.HttpServletRequest; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.ResponseBody; 
import com.ailk.sso.service.LoginManager; 
import com.google.code.kaptcha.Constants; 


@Controller 
@RequestMapping("/login") 
public class LoginController { 
@Autowired 
private LoginManager loginManager; 

@RequestMapping(value = "/login", method = RequestMethod.POST) 
@ResponseBody 
public String login(HttpServletRequest request, HttpServletRequest response , Model model) { 
System.out.println("userName=================="+request.getParameter("user"));
Map paras = new HashMap(); 
paras.put("user", request.getParameter("user")); 
paras.put("password", request.getParameter("password")); 
request.getSession().setAttribute("USERINFO", paras); 
String captchaId = (String) request.getSession().getAttribute("randcode"); 
String securityCode = request.getParameter("securityCode"); 
System.out.println(captchaId); 
System.out.println(securityCode); 
if(securityCode==null||!securityCode.equals(captchaId)){ 
model.addAttribute("loginMsg", ""); 
return "/login.jsp"; 
} 
Map loginMap = loginManager.authenticate(paras); 
if(loginMap!=null&&loginMap.get("loginMsg")!=null){ 
model.addAttribute("loginMsg", loginMap.get("loginMsg")); 
System.out.println(loginMap.get("loginMsg")); 
return "/login.jsp"; 
} 
model.addAllAttributes(loginMap); 
/*return "/portal.jsp";*/ 
return "/index.jsp"; 
} 
 } 

无力吐槽

还停留在Struts那里

@Controller
@RequestMapping("/login") 
public class LoginController {
……
@RequestMapping(value = "/login", method = RequestMethod.POST)
请问你哪里映射了 login/ login.action 啊

明明映射的是login/login

--- 共有 2 条评论 ---
小杨阿哥哥回复 @心&行 : 注解里不用带后缀. 5年前 回复
心_行正解 5年前 回复

解决方法一:


 <beanclass="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

   <property name="mappings">  
            <props>  
                <prop key="/login/login.action">这里填上你处理的control在XML里 id名称</prop>  
            </props>  

        </property> 

<bean>

第二张方法:

我看你既然你已经配置了MVC的注解驱动,但记得加上bean扫描类

直接在control上加上

@requestMapping("/login/login.action")


谢谢各位的热心回答,问题出现于@requestM apping ,本人是第一次真正使用Spring mvc 写东西,谢谢指点
--- 共有 1 条评论 ---
風一樣的男子解决了也不采纳答案,下次有人遇到类似问题了即使搜到你这个帖子了也不知道最终如果解决的,试问分享的意义何在? 5年前 回复
你的controller的映射名称和方法的映射名称不能一样    例如都叫login?      否则会出现找不到匹配的方法的错误

引用来自“aronshen”的评论

你的controller的映射名称和方法的映射名称不能一样    例如都叫login?      否则会出现找不到匹配的方法的错误
我说的版本是3.0.5     我在此版本遇到过这类问题 后来改为其他的  一切就OK了
顶部