package interceptor;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import cn.bdqn.entity.Employee;
public class StopLoginInterceptor implements HandlerInterceptor {
private List<String> excludeURIS;//白名单:未登录的情况下允许访问
public List<String> getExcludeURIS() {
return excludeURIS;
}
public void setExcludeURIS(List<String> excludeURIS) {
this.excludeURIS = excludeURIS;
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
boolean isok = false;
//1.获得请求的uri
String baseuri=request.getRequestURI();
String projecturi = request.getContextPath();
String uri = baseuri.replace(projecturi, "");
//2.请求URI是否在白名单中,是则放行,否则判断并拦截
if(this.excludeURIS.contains(uri)){
isok = true;
}else{
//3.判断session内置对象中是否在suserK-V
HttpSession session = request.getSession();
Employee users= session.getAttribute("user")==null?null:(Employee)session.getAttribute("user");
if(users != null){
isok = true;
}else{
//放置“提示信息”
session.setAttribute("errmsg", "会话异常,请重新登录!");
response.sendRedirect(request.getContextPath()+"/login.jsp");
}
}
return isok;
}
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex)
throws Exception {
// TODO Auto-generated method stub
}
}
最近下载更多
1271247100 LV9
11月22日
甜心冰淇淋 LV4
6月15日
微信网友_7321633020284928 LV2
1月1日
hongdongdong LV14
2024年6月12日
zhangbo2020 LV6
2023年11月22日
李亮 LV19
2023年8月28日
wddqwe LV1
2023年6月29日
微信网友_6505997864357888 LV3
2023年6月5日
ruoran7 LV1
2023年5月28日
qiangmin1223 LV12
2023年4月24日
最近浏览更多
1271247100 LV9
11月22日
vinlon
6月17日
暂无贡献等级
甜心冰淇淋 LV4
6月14日
shhhhhh
6月13日
暂无贡献等级
llxxyy
6月9日
暂无贡献等级
jhtxdy
5月4日
暂无贡献等级
hezhihui
1月9日
暂无贡献等级
微信网友_7321633020284928 LV2
1月1日
xiaoaitx LV8
1月1日
ma406805131 LV19
2024年12月27日

