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