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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值