SpringMVC拦截器(包括自定以拦截器--实现HandlerInterceptorAdapter)(资源和权限管理)
2018-02-07 21:43
429 查看
一,springmvc的配置
1 <!-- 访问拦截 --> 2 <mvc:interceptors> 3 <mvc:interceptor> 4 <mvc:mapping path="/**/**"/> 5 <bean class="com.fh.interceptor.LoginHandlerInterceptor"/> 6 </mvc:interceptor> 7 </mvc:interceptors>
二,拦截类
1 public class LoginHandlerInterceptor extends HandlerInterceptorAdapter{ 2 3 @Override 4 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 5 // TODO Auto-generated method stub 6 String path = request.getServletPath(); 7 if(path.matches(Const.NO_INTERCEPTOR_PATH)){ 8 return true; 9 }else{ 10 User user = (User)Jurisdiction.getSession().getAttribute(Const.SESSION_USER); 11 if(user!=null){ 12 path = path.substring(1, path.length()); 13 boolean b = Jurisdiction.hasJurisdiction(path); //访问权限校验 14 if(!b){ 15 response.sendRedirect(request.getContextPath() + Const.LOGIN); 16 } 17 return b; 18 }else{ 19 //登陆过滤 20 response.sendRedirect(request.getContextPath() + Const.LOGIN); 21 return false; 22 } 23 } 24 } 25 26 }
三,静态类
1 public static final String NO_INTERCEPTOR_PATH = ".*/((login)|(logout)|(code)|(app)|(weixin)|(static)|(main)|(websocket)).*"; //不对匹配该值的访问路径拦截(正则)
四,解释
只要进入Controller之前都会进入这个拦截器
相关文章推荐
- SpringMVC拦截器(包括自定以拦截器--实现HandlerInterceptorAdapter)(资源和权限管理)
- Spring MVC 中 HandlerInterceptorAdapter的使用[SpringMVC中请求拦截器的实现]
- SpringMVC拦截器(资源和权限管理)
- springmvc拦截器实现权限管理
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器2(资源和权限管理)(作为补充说明)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- (转载)SpringMVC拦截器(资源和权限管理)
- springMvc自定义拦截器HandlerInterceptorAdapter的认识
- springMvc拦截器(HandlerInterceptorAdapter)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)
- SpringMVC拦截器(资源和权限管理)