tank2140896 2013-07-09 20:25
浏览 268
已采纳

SpringMVC页面无法跳转

出现问题:SpringMVC页面无法跳转,老是报:
[WARN ] [19:58:55] org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/MVCdemo/user/login] in DispatcherServlet with name 'springMVC'
之前的项目也是这么写的,毫无问题,现在这个test项目也是简单模仿的,连Hibernate数据库都没用,居然出现这个问题,百度、google搜寻也无果,解决不了。。。下面贴几段核心配置和写法,完整程序见附件,导包的话只要导spring最新版本即可。
1、web.xml
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
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">
<!-- Character Encoding filter -->



EncodingFilter

org.springframework.web.filter.CharacterEncodingFilter



encoding

UTF-8




forceEncoding

true






EncodingFilter

/*


<!-- 加载所有Spring配置文件 -->

contextConfigLocation

/WEB-INF/config/spring-common.xml


<!-- 配置spring监听 -->




org.springframework.web.context.ContextLoaderListener




<!-- 配置SpringMVC -->



springMVC

org.springframework.web.servlet.DispatcherServlet



contextConfigLocation

/WEB-INF/config/spring-common.xml



1





springMVC

/



[/code]
2、spring-common.xml
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 声明使用注解的风格 -->
context:annotation-config/
<!-- 开启mvc注解 -->

<!-- 静态资源(js/image)的访问 -->



<!-- 定义视图解析器 -->










[/code]
3、UserLoginAction
[code="java"]
package com.study.action;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.study.service.UserService;

@Controller
@RequestMapping("/user")
public class UserLoginAction{

@Resource(name="userService")
private UserService userService;

@RequestMapping("/login")
public String login(String username,String password,HttpServletRequest request){
    boolean b = userService.search(username,password);
    if(b==true){
        request.setAttribute("username",username);
        return "/ppp/success";
    }else{
        return "/ppp/fail"; 
    }
}

}
[/code]
4、index.jsp
[/code]


用户名

密  码



[/code]
  • 写回答

2条回答

  • raychou86 2013-07-09 23:20
    关注

    spring配置文件里加上

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题