700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > shiro登陆失败提示_shiro在springMVC 如何处理登陆失败跳到登陆页面呢?

shiro登陆失败提示_shiro在springMVC 如何处理登陆失败跳到登陆页面呢?

时间:2024-06-03 01:21:53

相关推荐

shiro登陆失败提示_shiro在springMVC 如何处理登陆失败跳到登陆页面呢?

我的登陆的方法:

@RequestMapping(value = "/dologin.req")

public String doLogin(HttpServletRequest request, Model model) {

String msg = "";

String userName = request.getParameter("userName");

String password = request.getParameter("password");

UsernamePasswordToken token = new UsernamePasswordToken(userName, password);

token.setRememberMe(true);

Subject subject = SecurityUtils.getSubject();

try {

subject.login(token);

if (subject.isAuthenticated()) {

return "redirect:/home.req";

} else {

return "login";

}

} catch (IncorrectCredentialsException e) {

msg = "登录密码错误. Password for account " + token.getPrincipal() + " was incorrect.";

model.addAttribute("message", msg);

System.out.println(msg);

} catch (ExcessiveAttemptsException e) {

msg = "登录失败次数过多";

model.addAttribute("message", msg);

System.out.println(msg);

} catch (LockedAccountException e) {

msg = "帐号已被锁定. The account for username " + token.getPrincipal() + " was locked.";

model.addAttribute("message", msg);

System.out.println(msg);

} catch (DisabledAccountException e) {

msg = "帐号已被禁用. The account for username " + token.getPrincipal() + " was disabled.";

model.addAttribute("message", msg);

System.out.println(msg);

} catch (ExpiredCredentialsException e) {

msg = "帐号已过期. the account for username " + token.getPrincipal() + " was expired.";

model.addAttribute("message", msg);

System.out.println(msg);

} catch (UnknownAccountException e) {

msg = "帐号不存在. There is no user with username of " + token.getPrincipal();

model.addAttribute("message", msg);

System.out.println(msg);

} catch (UnauthorizedException e) {

msg = "您没有得到相应的授权!" + e.getMessage();

model.addAttribute("message", msg);

System.out.println(msg);

}

return "login";

}

登陆错误的时候:

我的springmvc下返回目录views下,的确没有login.jsp,应为login.jsp如图已经在web-app下。

那么如何设置登陆错误 跳回login.jsp下呢?

下面是我的shiro的配置文件:

/dologin.req = anon

/**=authc

/WEB-INF/views/=authc

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。