求救,springMVC为什么一直报找不到controller

qq_17039229 2015-08-31 05:30:33
看着视频自学springMVC,但是现在总是报这个错误 No mapping found for HTTP request with URI [/springMVC2/user/data/toUser] in DispatcherServlet with name 'springMVC2',网上的各种方法都试过了。实在是没办法了,求大神帮忙……
package com.rfid.annotion;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user/data")
public class SpringAnntion {

@RequestMapping("/addUser")
public String addUser(String userName,String password,HttpServletRequest request){

request.setAttribute("userName", userName);
request.setAttribute("password", password);
return "/userManager";
}

@RequestMapping("/delUser")
public String delUser(HttpServletRequest request){
String result ="this is delUser------优化版";
request.setAttribute("result", result);
return "/jquery";
}
@RequestMapping("/toUser")
public String toUser(HttpServletRequest request){
return "/addUser";
}
}


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function addUser(){
var form = document.forms[0];
form.action = "/springMVC2/user/data/addUser";
form.method = "get";
form.submit();
}
</script>
</head>
<body>
<form action="">
用户名 :<input type="text" name="userName" />
密码:<input type="password" name="password" />

<input type="button" value="提交" onclick="addUser"/>
</form>


</body>
</html>

[code=text]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>springMVC1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>springMVC2</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>

<!--<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>-->

<servlet-mapping>
<servlet-name>springMVC2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
[code=text]
<?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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 注解扫描包 -->
<context:component-scan base-package="com.rfid.annotion" />
<!-- 开启注解 -->
<mvc:annotation-driven/>

<mvc:default-servlet-handler/>

<!-- 静态资源访问 -->
<mvc:resources location="/img/" mapping="/img/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>


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

[/code]
[/code]
...全文
1282 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChrisChen_ 2015-10-29
  • 打赏
  • 举报
回复
楼主,你的tomcat是什么问题?我的也是这个问题一直解决不了,配置都检查过很多遍了没什么问题
qq_22105541 2015-09-02
  • 打赏
  • 举报
回复
路径出错了
chenhao237 2015-09-02
  • 打赏
  • 举报
回复


<form action="${pageContext.request.contextPath}/你的路径">

</form>
很明显路径不对
qq_17039229 2015-09-02
  • 打赏
  • 举报
回复
引用 2 楼 zw0283的回复:

<script type="text/javascript">
    function addUser(){
        var form = document.forms[0];
        form.action = "/springMVC2/user/data/addUser";
        form.method = "get";
        form.submit();
    }
</script>
这里的路径错了吧。。应该写成springMVC2/user/data/addUser 我这么看你的代码写的没什么问题啊。。应该就是路径错了吧
问题已经解决了,是tomcat的问题,不过还是得谢谢你们
天空趋虚 2015-09-01
  • 打赏
  • 举报
回复
springMVC2是什么鬼,根据你的web.xml你要写也写springVMC1啊,或者项目直接放ROOT下,不写项目名。
zw0283 2015-09-01
  • 打赏
  • 举报
回复

<script type="text/javascript">
    function addUser(){
        var form = document.forms[0];
        form.action = "/springMVC2/user/data/addUser";
        form.method = "get";
        form.submit();
    }
</script>
这里的路径错了吧。。应该写成springMVC2/user/data/addUser 我这么看你的代码写的没什么问题啊。。应该就是路径错了吧
liangzhenhuang 2015-09-01
  • 打赏
  • 举报
回复
<form action="???">????

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧