CRM登录认证拦截器全局异常(登录认证拦截器)

1 需求分析

依据用户信息储存标准,根据拦截器拦截用户实际操作要求获得用户cookie信息,获取cookie 中用户id 用户纪录存有性校验, 校验不成功,抛出去自定义异常信息,撰写用户自定义异常类,捕获系统异常信息并对自定义异常做相对应网页页面回应解决。,servlet-context.xml配备自定 出现异常与登陆拦截器,完成用户登陆要求拦截校验作用

2 servlet-context.xml<mvc:interceptors> <mvc:interceptor> <mvc: ** pping path="/**"/> <mvc:exclude- ** pping path="/index"/> <mvc:exclude- ** pping path="/user/userLogin"/> <mvc:exclude- ** pping path="/css/**"/> <mvc:exclude- ** pping path="/jquery-easyui-1.3.3/**"/> <mvc:exclude- ** pping path="/i ** ges/**"/> <mvc:exclude- ** pping path="/js/**"/> <bean class="com.xxx.crm.interceptors.LoginInterceptor"/> </mvc:interceptor> </mvc:interceptors>

3 流程表

4 撰写LoginInterceptorpublic class LoginInterceptor extends HandlerInterceptorAdapter{ @Resource public UserService userService; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String userId= CookieUtil.getCookieValue(request,"userId"); AssertUtil.isTrue(null==userId,"用户未登录"); userId=Base ** Util.decode(userId); User user = userService.queryUserById(userId); AssertUtil.isTrue(null==user,"用户不会有"); return true;//全局性出现异常 } }喜爱就关心嗨码歌吧!每日都是新的技术性与你共享哦!

Copyright 2021 快鲸

扫码免费用

源码支持二开

申请免费使用

在线咨询