关于拦截器的内容

在拦截点进行拦截,如果返回True,则不执行拦截点后的操作(拦截成功)
        // 返回false 则表示不拦截
        HttpSession session = request.getSession();
        // 1. 拦截点: 从我们项目发起的url
        String uri = request.getRequestURI();
//        if(session.getAttribute("userInfo")!=null || uri.indexOf("user/doLogin.do")!=-1){// indexOf - 路径在字符串内出现的下标
        if(session.getAttribute("userInfo")!=null){
            // 登录成功, 不拦截。
            return true;
        }else {
            // 拦截后进入登录页面
            response.sendRedirect(request.getContextPath()+"/user/doLogin.do");
            return false;
        }

结果截图:

猜你喜欢

转载自blog.csdn.net/qq_42254122/article/details/94755935