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

来源:互联网 发布:手机淘宝怎么备注留言 编辑:程序博客网 时间:2024/05/21 17:23

注:转载请注明出处,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

0 0
原创粉丝点击