Safari不能保存session,每创建一个新的页面就会创建新的session,就登陆不了
有没有人解决过类似问题?
8 回复
解决方案
老的代码是:
HttpSession session = Mvcs.getHttpSession(false);
if (session == null) {
re.setv("msg", "session已过期");
String temp = head+Json.toJson(re, JsonFormat.compact())+tail;
return temp;
}
新的代码是:
HttpSession session = request.getSession();
if (request.getParameter("JSESSIONID") != null) {
Cookie userCookie = new Cookie("JSESSIONID", request.getParameter("JSESSIONID"));
response.addCookie(userCookie);
} else {
String sessionId = session.getId();
Cookie userCookie = new Cookie("JSESSIONID", sessionId);
response.addCookie(userCookie);
}
// session是否有效
// HttpSession session = Mvcs.getHttpSession(false);
if (session == null) {
re.setv("msg", "session已过期");
String temp = head+Json.toJson(re, JsonFormat.compact())+tail;
return temp;
}
添加回复
请先登陆