原文:http://www.cnblogs.com/jarl/p/5892996.html
HttpSession session = request.getSession();
session.setAttribute(user, user);
session.setMaxInactiveInterval(2 * 3600); // Session保存两小时
Cookie cookie = new Cookie("JSESSIONID", session.getId());
cookie.setMaxAge(2 * 3600); // 客户端的JSESSIONID也保存两小时
session.setMaxInactiveInterval(interval);
cookie.setPath("/");
response.addCookie(cookie);