1 Cookie cookie = new Cookie("username",username); 2 cookie.setMaxAge(60 * 60 * 24 * 365 * 2);//设置cookie保存时间 3 cookie.setPath("/");//cookie有效路径是网站根目录 4 con.getResponse().addCookie(cookie);//向客户端写入cookie 5 con.setSessionAttr("userLogin", model);
1 HttpSession session = request.getSession(); 2 session.setMaxInactiveInterval(60*60);//session过期时间 3 session.setAttribute("userLogin", model);