Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.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
Java Set Cookie标头未在Internet Explorer中设置Cookie_Java_Http_Internet Explorer_Cookies_Jersey - Fatal编程技术网

Java Set Cookie标头未在Internet Explorer中设置Cookie

Java Set Cookie标头未在Internet Explorer中设置Cookie,java,http,internet-explorer,cookies,jersey,Java,Http,Internet Explorer,Cookies,Jersey,我正在尝试使用set cookie头设置cookie服务器端 使用jersey将cookie设置为服务器端,如下所示: NewCookie cookie = new NewCookie("token", tokenValue, "/", "", 1, "", 3600, new Date(System.currentTimeMillis() + 3600000), false, false); return Response.ok() .cookie(cooki

我正在尝试使用set cookie头设置cookie服务器端

使用jersey将cookie设置为服务器端,如下所示:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", "", 1, "", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);
return Response.ok()
                .cookie(cookie)
                .build();
我在Chrome中的响应标题如下所示:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", "", 1, "", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);
return Response.ok()
                .cookie(cookie)
                .build();

当我尝试向服务器发送另一个请求时,为了检查cookie是否被发回,一切都按预期进行。请求标头如下所示:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", "", 1, "", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);
return Response.ok()
                .cookie(cookie)
                .build();

Firefox和Opera浏览器也表现出同样的行为。虽然,当我尝试Internet Explorer时,还有另一个故事

第一个请求的响应头:

第二个请求的标题:

基本上没有请求头,cookie也没有设置。。。 我放饼干的时候做错什么了吗?我尝试过其他类似问题的各种解决方案,但似乎没有任何效果

编辑:

通过禁用保护模式更改了IE Internet选项并允许所有cookie,但仍然没有

编辑2:

在不同的计算机上尝试,我得到了不同的结果。在某些计算机中,它可以正常工作,而在某些计算机中则不能。Internet Explorer上一定有我丢失的一些设置。尽管如此,无论我如何尝试,我都无法让它在
localhost
上工作

解决方案

显然,正如dabaicai所评论的,不应该有任何空的属性值文件。当我创建cookie时,
注释
属性有空值:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", "", 1, "", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);
我把它改成:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", httpServletRequest.getServerName(), 1, "no-comment", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);

现在,在Internet Explorer中,一切都如预期的那样工作

我认为由于域
localhost
,您可以尝试使用127.0.0.1访问URL,然后查看结果。

您还没有?没有,没有工作。。。我已经试过127.0.0.1了。我还在hosts文件中为localhost设置了一个不同的名称,但仍然没有设置任何内容……您是否访问了其他计算机上的页面?您是对的!当我从另一台计算机访问链接时,它可以工作!但当我尝试localhost时,它失败了…rfc6265指示属性值是否为空,行为是否未定义。因此浏览器可以放弃域。您的意思是,如果域属性的注释具有空值,可能会导致问题?