springmvc拦截器跳转问题

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也得刷新一下页面才能拿得到,感觉好影响项目效率。在线等,好急啊,做了好几天没解决。

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!