开发者

Cookie available only in firefox

I set a cookie in a Struts Action using:

Cookie c = new Cookie("CODE","1");
c.setPath("/");
c.setMaxAge(120);
response.addCookie(c);

And in a asp page, running in the same domain I have the following asp code:

response.write(Request.Cookies("CODE"))

The funny thing is that the cookie is correctly written only when I load the asp using f开发者_C百科irefox. Neither chrome nor ie9 show it properly - cookies are enabled in all three browsers.

What can be happenning ? Thanks in advance


Please try this set and get cookie in Javascript, It will help you.

setCookie("myCookie", "test Data", 3660);

getCookie("myCookie")

// Set Cookie Value    
function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

// Get Cookie Value
function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜