首页 > 其他分享 >Session

Session

时间:2023-01-14 17:56:20浏览次数:39  
标签:utf name Session resp req setCharacterEncoding session

 

 

 

 

 

 

 

Session还可以通过setAttribute()保存用户信息

 

req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("Content-type","text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        HttpSession session = req.getSession();
        session.setAttribute("name",new Person("郭江龙",1));
        String sessionId= session.getId();
        if (session.isNew()){
            writer.write("session已经创建创建成功"+sessionId);
        }else {writer.write("session已经在服务器中存在了 ID:"+sessionId);
        }
 req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("Content-type","text/html;charset=utf-8");
        HttpSession session = req.getSession();
        Person name = (Person) session.getAttribute("name");
        System.out.println(name.toString());

 

标签:utf,name,Session,resp,req,setCharacterEncoding,session
From: https://www.cnblogs.com/guojianglong/p/17052283.html

相关文章