Java 响应中的Internet Explorer Cookie未覆盖现有Cookie
我有一个客户机-服务器web应用程序,其中来自服务器的每个响应都将包含一个名为Java 响应中的Internet Explorer Cookie未覆盖现有Cookie,java,rest,http,cookies,dojo,Java,Rest,Http,Cookies,Dojo,我有一个客户机-服务器web应用程序,其中来自服务器的每个响应都将包含一个名为fruitCookie的Cookie 但是,在服务器上,100次中有90次将Cookie设置为: Cookie cookie = new Cookie("fruitCookie", "someRefreshedValue"); cookie.setPath("/"); httpResponse.addCookie(cookie); 其中Cookie是javax.servlet.http.Cookie 但是,在服务器上
fruitCookie
的Cookie
但是,在服务器上,100次中有90次将Cookie
设置为:
Cookie cookie = new Cookie("fruitCookie", "someRefreshedValue");
cookie.setPath("/");
httpResponse.addCookie(cookie);
其中Cookie
是javax.servlet.http.Cookie
但是,在服务器上剩余的10次,Cookie
将从rest端点设置为:
NewCookie fruitCokie = new NewCookie("fruitCookie", "someRefreshedValue", "/", "", "", -1, false);
return Response.ok().cacheControl(ResourceCache.NO_CACHE).cookie(fruitCookie).build();
其中NewCookie是javax.ws.rs.core.NewCookie
在客户端,我使用dojo读取cookie作为:
getCookieValue: function (cookieName) {
return cookie(cookieName); // cookieName is fruitCookie
},
这在Chrome
中运行良好。在上述函数中读取来自http way或Rest的最新Cookie
值
然而,在IE中,它不起作用。如果rest调用发送Cookie
,我可以在dev控制台上看到新的Cookie
响应,但是,上面的调用会继续返回浏览器上已经存在的旧值以及发送的部分请求
我不确定是IE浏览器造成的,还是它与路径和域有关,或者是DojoCookie小部件的工作方式
我如何解决这个问题?显然,IE非常关心域 所以改变一下
NewCookie fruitCokie = new NewCookie("fruitCookie", "someRefreshedValue", "/", "", "", -1, false);
到
工作如期进行
我们可以在Rest中获取httpRequest
,如下所示:
@GET
@Path("myPath")
public Response myRestEndPoint(@Context HttpServletRequest httpRequest) {
注意:这在“localhost”上不起作用。请参考:显然,IE非常关心域名 所以改变一下
NewCookie fruitCokie = new NewCookie("fruitCookie", "someRefreshedValue", "/", "", "", -1, false);
到
工作如期进行
我们可以在Rest中获取httpRequest
,如下所示:
@GET
@Path("myPath")
public Response myRestEndPoint(@Context HttpServletRequest httpRequest) {
注意:这在“localhost”上不起作用。请参阅: