search

Home  >  Q&A  >  body text

java - I encountered a problem while writing code today, that is, an object that was just saved into the session cannot be read out. I would like to ask what the problem is.

I made a login today and saved it with session in the background. I don’t know why I can’t get it and it’s still null.

@ResponseBody
@RequestMapping("/ueserLogin")
public Object ueserLogin(Model model){
    Users userss;    
    System.out.println(request.getParameter("user_number"));
    if(request.getParameter("user_number")!=null && request.getParameter("user_number")!=""){
        userss=userbiz.findUserByNume(request.getParameter("user_number"));
        if(userss!=null){
            //这里我用session保存
            request.getSession().setAttribute("users", userss);
            //输出是null ![图片描述][1]
            System.out.println(request.getParameter("users"));
            //还强转不了为对象
            //(Users)request.getParameter("users");
            return JSON.toJSONString(userss);
        }else{
            return "no";
        }
    }else{
        System.out.println("账号不能为空!");
        return "no";
    }
}
大家讲道理大家讲道理2749 days ago753

reply all(1)I'll reply

  • typecho

    typecho2017-06-10 09:50:02

    Of course the objects you store in session cannot be retrieved using request.

    request.getSession().getAttribute("users"); // 试试

    reply
    0
  • Cancelreply