No mapping found for HTTP request with URI [/chapter2/loginCheck] in Dispatc

首先在spring-mvc.xml文件 中配置 扫描类包

然后jsp代码如下

<form action="<c:url value="/loginCheck"/>" method="post">
    用户名:<input type="text" name="userName">
    <br>
    密码:<input type="password" name="password">
    <br>

    <input type="submit" value="登录"/>
    <input type="reset" value="重致"/>
form>


最后在control中如下写

@RequestMapping(value="/loginCheck")
public ModelAndView loginCheck(HttpServletRequest request,LoginCommand loginCommand){
    boolean isValidUser = userService.hasMatchUser(loginCommand.getUserName(),loginCommand.getPassword());
    if(!isValidUser){
        return new ModelAndView("login","error","用户名或是密码错误");
    }else{
        User user = userService.findUserByUserName(loginCommand
                .getUserName());
        user.setLastIp(request.getLocalAddr());
        user.setLastVisit(new Date());
        userService.loginSuccess(user);
        request.getSession().setAttribute("user", user);
        return new ModelAndView("jsp/main");
    }
}

既然报错“No mapping found for HTTP request with URI [/chapter2/loginCheck] in Dispatch”,最后查找后发现是在spring-mvc.xml文件中的扫描代码出错

这个要改写成

没有理解什么原因了。

你可能感兴趣的:(spring)