0 0

ff与google浏览器取不到cookie值10

A.servlet设置cookie
//保存参数
Enumeration em= (Enumeration)httpRequest.getParameterNames();  
while(em.hasMoreElements()) {  
String parName=(String)em.nextElement();  
String value= httpRequest.getParameter(parName);
System.out.println("-----"+parName);
System.out.println("-----"+value);

Cookie cookie = new Cookie(parName, value);
cookie.setMaxAge(60*60*2);
cookie.setPath("/");
httpResponse.addCookie(cookie);
}  
B.servelt取值
  Cookie[] cookies = httpRequest.getCookies();
for (int i = 0; i < cookies.length; i++) {
System.out.println("xxxx----"+cookies[i].getName());
System.out.println("xxxx----"+cookies[i].getValue());
}
同样代码,IE下能取到,ff与google浏览器,求解
2012年3月20日 10:00

2个答案 按时间排序 按投票排序

0 0

确认一下浏览器有没有禁用cookie?

2012年3月20日 16:08
0 0

估计是游览器的问题吧。看到网上还有种方法,你看看

   var localData = {
    _oIe : null,
    _areaIe : "defaultSaveArea",
    _expires : 365,
    _isFF : !!(/firefox/i.test(navigator.userAgent)),
    _isIE : !!(/msie/i.test(navigator.userAgent)),
    _empty: function(v){ return (typeof(v)=='undefined'||v==null||v=='');},
    init : function () { 
        if( this._isIE && !this._oIe ){
            this._oIe = document.documentElement;
            this._oIe.addBehavior("#default#userdata");
        }
    },
    save : function (key, value, time, domain, path){
        this.init();
        if( this._empty(key) ){ return false; }
        if(this._isFF && sessionStorage){ 
            sessionStorage.setItem(key,value);
        }else if(this._isIE){
            var oTimeNow = new Date();
            oTimeNow.setMinutes(oTimeNow.getMinutes() + this._expires*24*60);
            var sExpirationDate = oTimeNow.toUTCString();
            this._oIe.expires = sExpirationDate;
            this._oIe.setAttribute(key,value);
            this._oIe.save(this._areaIe);
        }else{
            setCookie(key, value, time, domain, path);
        }
    },
    get : function (key){
        this.init();
        if( this._empty(key) ){ return false; }
        if(this._isFF  && sessionStorage ){ 
            var o = sessionStorage.getItem(key);
            return o ? o.value : "";
        }else if(this._isIE){
            this._oIe.load(this._areaIe);
            return this._oIe.getAttribute(key);
        }else{
            return getCookie(key);
        }
    },
    del : function (key, domain, path){
        this.init();
        if( this._empty(key) ){ return false; }
        if(this._isFF && sessionStorage ){ 
            sessionStorage.removeItem(key);
        }else if(this._isIE){
            this._oIe.setAttribute(key,"");
            this._oIe.save(this._areaIe);
        }else{
            delCookie(key, domain, path);
        }
    }
};

2012年3月20日 11:37

相关推荐

Global site tag (gtag.js) - Google Analytics