Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chrome浏览器:未从响应头设置cookie_Javascript_Google Chrome_Cookies - Fatal编程技术网

Javascript Chrome浏览器:未从响应头设置cookie

Javascript Chrome浏览器:未从响应头设置cookie,javascript,google-chrome,cookies,Javascript,Google Chrome,Cookies,在服务器端创建cookie,然后添加到响应: Cookie cookie = new Cookie("foo", "bar"); cookie.setPath("/abc"); cookie.setDomain(request.getServerName()); cookie.setSecure(request.isSecure()); cookie.setMaxAge(24 * 60 * 60 * 90); // 90 days respons

在服务器端创建cookie,然后添加到响应:

    Cookie cookie = new Cookie("foo", "bar");
    cookie.setPath("/abc");
    cookie.setDomain(request.getServerName());
    cookie.setSecure(request.isSecure());
    cookie.setMaxAge(24 * 60 * 60 * 90); //  90 days
    response.addCookie(cookie);
响应头:(非ajax)从浏览器开发人员工具中看到

Content-Type:text/html;charset=UTF-8
Date:Wed, 25 Feb 2015 07:13:12 GMT
Server:Apache-Coyote/1.1
Set-Cookie:foo="bar"; Version=1; Domain=localhost; Max-Age=7776000; Expires=Tue, 26-May-2015 07:13:12 GMT; Path=/abc
但是从开发工具>资源>cookies,cookie没有显示出来


非常感谢您的帮助。

即使我也编写了相同的代码,但cookie没有显示出来

当我打印我的回复时,我会得到值,但我无法在我的chrome浏览器上看到

服务器端代码:

Cookie lastConnetionDateCookie = createCookie("lastConnetionDate", lastLoginDate);
            response.addCookie(lastConnetionDateCookie);

            Cookie creationDateCookie = createCookie("creationDate", userCreationDate);
            response.addCookie(creationDateCookie);

            Cookie servicesCookie = createCookie("services", StringUtils.join(services, "|"));
            response.addCookie(servicesCookie);

            _log.info(response);
Ajax代码:

function setUserCookies() {
    JQ.ajax({
        type: 'POST',
        url: 'http://.....',
        data: formToJSON,
        contentType:'application/json',
        /* xhrFields: {
            withCredentials: true
        }, */
        crossDomain: true,
        success: function(data, textStatus, jqXHR){
             console.log('Cookie created successfully');
          },
        error: function(jqXHR, textStatus, errorThrown){
             console.log('setUserCookies error : ' + textStatus);
        }
    });
}

function formToJSON() {
    return ${userCookies};
}

一些问题:1。您是否自己创建
设置cookie
字符串?2.是否从本地主机返回响应?3.此域中是否有其他cookie?4.对于
Version=1的内容?已编辑。我没有设置版本,它是由CookieAPI隐式添加的。服务器名称为localhost。