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条)

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services