When the login picture is verified, the value of the Session is null when fetched

When logging in and verifying Session verification, the value is null when fetched

reason

When we verify the picture, when we generate the verification code picture, we store the verification code information in the session. When we click to log in, we take out the session passed to the back end and compare it with the verification code information entered by the front end. Yes, but every time you click to log in, the login fails. We break the point and find that the verification code we got from the session is null. This is due to the problem that we use Google Chrome. Due to the high security level of Google Chrome, we will not carry cookies when we cross domains, so when we take out the session, it will be null when we take it out, that is, every time we If it is null for the first time, you cannot log in. Let's change the browser.

//获取登录验证需要的参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String imageCode = req.getParameter("imageCode");
        System.out.println("=="+imageCode);

        //判断验证码是否正确
        //取session中的验证
        HttpSession session = req.getSession();
        String verCode = (String) session.getAttribute("verCode");
        System.out.println("22"+verCode);
        if(imageCode.equalsIgnoreCase(verCode)){
    
    
            //验证码通过
            //调用底层的验证方法
            User user = us.findByUsernameAndPassword(username, password);
            if(user!=null){
    
    
                //判断用户身份
                if(user.getStatus()==1&&user.getRole()==1){
    
    
                    //登录成功
                    vo = new ResultVo(200,"登录成功",user);
                }else{
    
    
                    vo = new ResultVo(500,"该用户权限出错",null);
                }
            }else{
    
    
                vo = new ResultVo(500,"账号或密码有误",null);
            }
        }else{
    
    
            vo = new ResultVo(500,"验证码输入有误",null);
        }

Guess you like

Origin blog.csdn.net/qq_51753851/article/details/129333054