尝试使用shiro管理权限,写了一个简单的登录方法,
@RequestMapping(value = "/signin")
public String signin(HttpServletRequest request) throws Exception
{
String exceptionClassName = (String) request.getAttribute("shiroLoginFailure");
logger.debug("异常信息:" + exceptionClassName);
if (exceptionClassName != null)
{
if (UnknownAccountException.class.getName().equals(exceptionClassName))
{
//最终会抛给异常处理器
throw new CustomException("账号不存在");
}
else if (IncorrectCredentialsException.class.getName().equals(exceptionClassName))
{
throw new CustomException("用户名/密码错误");
}
else if ("randomCodeError".equals(exceptionClassName))
{
throw new CustomException("验证码错误 ");
}
else
{
throw new Exception();//最终在异常处理器生成未知错误
}
}
return "/signin";
}
使用springmvc的全局异常处理,要跳转到一个错误页面去。
但是我想做的是,登录发生了错误,还是返回到登录页面,并显示错误信息。这个功能用其他方式很好做,但是用shiro搞了半天都没有做出来。
求助,是我的思路错了吗,shiro怎么实现这样的需求?
全局异常处理器捕获异常 return modelandview