首页>代码>ssm整合apache shiro开发用户登录权限认证的实例demo>/ShiroDemo/src/com/gjp/exception/MyException.java
package com.gjp.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/**
 * 自定义异常拦截器
 */
@Component
public class MyException extends Exception implements HandlerExceptionResolver
{
	private static final long serialVersionUID = 1L;

	private String message;

	public MyException()
	{
	}

	public MyException(String message)
	{
		super(message);
		this.message = message;
	}

	@Override
	public String getMessage()
	{
		return message;
	}

	public void setMessage(String message)
	{
		this.message = message;
	}

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
	{
		// handler为当前处理器适配器执行的对象
		String message = null;

		// 判断异常类型,并做相应错误消息截取。
		if (ex instanceof UnauthorizedException)
		{
			//没有相应权限
			message = ((UnauthorizedException) ex).getMessage();
		}else
		{
			message = "系统出错啦,稍后再试试!错误信息:"+ex.getMessage();
		}

		ModelAndView modelAndView = new ModelAndView();
		// 跳转到相应的处理页面
		modelAndView.addObject("errorMsg", message);
		modelAndView.setViewName("unauthorized");
		return modelAndView;
	}
}
最近下载更多
sweetbox  LV10 2022年7月11日
543666826  LV33 2021年11月20日
adasdsda  LV1 2021年9月26日
303661956  LV11 2020年7月6日
wsk588  LV26 2020年6月8日
卡卡罗特  LV8 2020年5月7日
liuwenlong  LV20 2020年4月21日
2945624210  LV2 2020年3月27日
cainame  LV11 2020年3月17日
yingyingya  LV3 2020年3月10日
最近浏览更多
fire1234  LV2 3月5日
森sdfgf  LV8 2023年6月28日
女王不该在山炮村养花  LV8 2023年4月13日
139465  LV12 2023年4月3日
Wu_大花  LV1 2023年3月26日
LITIANYU084414  LV11 2023年1月4日
qq1176648922  LV6 2022年12月28日
wz520135  LV7 2022年12月22日
邬松桥  LV11 2022年11月17日
sweetbox  LV10 2022年7月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友