标签:als 顺序 request 意思 cto exception pre property prope
自定义拦截器类public SessionInterceptor() {
// TODO Auto-generated constructor stub
}
private List<String> excludedUrls;
//通过属性注册不需要过滤的url list
public void setExcludedUrls(List<String> excludedUrls) {
this.excludedUrls = excludedUrls;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
String requestUrl = request.getRequestURI();
//排除不需要过滤的URL
for(String url:excludedUrls) {
if(requestUrl.endsWith(url)) {
return true;
}
}
//获取当前的会话session
HttpSession session = request.getSession();
if(session.getAttribute("userid") == null) {
//若登录session过期或不存在就跳转到login页面
request.getRequestDispatcher("/login.jsp").forward(request, response);
return false;
}
return true;
}
}
springmvc-servlet.xml 拦截器注册
<mvc:interceptors>
<mvc:interceptor>
标签:als 顺序 request 意思 cto exception pre property prope
原文地址:https://blog.51cto.com/6000734/2355681