public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
HttpSession session = httpServletRequest.getSession();
Object UserId = session.getAttribute("userId");
String InterUri = httpServletRequest.getServletPath();
String requesturl = httpServletRequest.getRequestURI();
String contextpath = httpServletRequest.getContextPath();
String url = requesturl.substring(contextpath.length());
if ( null ==UserId){
if (httpServletRequest.getCookies()!=null) {
Cookie[] cookies = httpServletRequest.getCookies();
if (cookies != null && cookies.length > 0) {
String usercook = null;
for (Cookie cookie : cookies) {
if ("UserCookie".equals(cookie.getName())) {
usercook = cookie.getValue();
String[] Susercook = usercook.split(",");
if (Susercook.length == 3) {
int userId = Integer.parseInt(Susercook[0]);
User user = userService.findbuId(userId);
String username = Susercook[1];
String password;
if (username.indexOf("@") > 0) {
password = Susercook[2];
if (username.equals(user.getEmail()) && password.equals(user.getPassword())) {
session.setAttribute("UserId", userId);
break;
}
} else {//手机登录
password = Susercook[2];
if (username.equals(user.getPhone()) && password.equals(user.getPassword())) {
session.setAttribute("userId", userId);
break;
}
}
}
}
}
if (usercook!=null){
return true;
}
}
}
}
else{//id
// httpServletResponse.sendRedirect(httpServletRequest.getContextPath() +"/Main.jsp");
if(null != allowUrls && allowUrls.length>=1){
for(String path : allowUrls) {
if(url.contains(path)) {
return true;
}
}
}
}
return true;
}
有没有大神帮下忙,为什么 responsesendredirect(页面)根本没反应 还不能return false,不然静态资源又会被拦截,跳页面时候 httpServletRequest.getServletPath();全是静态资源路径没有跳转的页面路径,我的跳转不经过controller跳转,直接页面跳页面,session也得刷新一下页面才能拿得到,感觉好影响项目效率。在线等,好急啊,做了好几天没解决。