您的位置:首页 > 其它

IE浏览器下使用localhost域名保存cookie的问题

2016-12-02 19:49 555 查看
注:转载请注明出处,http://blog.csdn.net/huyi0616/article/details/53438435

最近在做一个新项目,发现在IE浏览器下无法单点登录,经过源码查看追踪,发现如下代码问题

SessionConfig.java

private Integer redisExpireTime = 60 * 60 * 24 * 7;
private Integer cookieExpireTime = 60 * 60 * 2;
private Integer cookieMaxAge = -1;
private String cookieDomain = "localhost";
private String cookiePath = "/";


SessionManager.java

Cookie refreshTimeCookie = new Cookie(REFRESH_TIME_COOKIE_KEY,     String.valueOf(System.currentTimeMillis()));
refreshTimeCookie.setMaxAge(sessionConfig.getCookieMaxAge());
refreshTimeCookie.setPath(sessionConfig.getCookiePath());
refreshTimeCookie.setDomain(sessionConfig.getCookieDomain());
response.addCookie(refreshTimeCookie);


login.js

var login = function() {
if(!$("#account").val() || !$("#pwd").val()) {
$('#error-msg').text("用户名及密码不能为空.").show();
return;
}

var loginParam = $('#login-form').find('input').serialize();
console.log(loginParam);
$.ajax({
method : 'POST',
url : 'account/login',
data : loginParam,
success : function(result) {
if (result && result.code=='0') {
console.log(getUrlParameter('requestURL'));
window.location.href = getUrlParameter('requestURL') + window.location.hash;
$('#error-msg').text('').hide();
} else {
$('#error-msg').text(result.msg).show();
}
}
});
}


现象:

在chrome,firefox浏览器下,设置cookie的domain为localhost时是可以正常保存cookie,但IE是无法保存

总结:

1. 在cookie设置域名domain为localhost时,IE浏览器无法保存cookie

2. 设置项目代码为localhost时,使用http://localhost:8080/访问,不论你domain设置为什么,IE浏览器同样无法保存cookie

解决方案:

1.修改host文件,修改增加本地的域名对应到127.0.0.1

如:

127.0.0.1    www.360qq.com


2.不要使用localhost开发IE
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cookie 浏览器 ie