从Java设置持久性cookie在IE中不起作用 [英] Setting persistent cookie from Java doesn't work in IE

查看:589
本文介绍了从Java设置持久性cookie在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

虽然我在论坛上看到相关主题,但我没有看到这个问题的明确解决方案。
我试图设置一个javax.servlet.http.Cookie的过期时间(以便它在浏览器会话中持久化)。代码:

Although I see related topics on the forum, but I don't see a clear solution on this issue. I am trying to set a javax.servlet.http.Cookie with an expiration time (so that it persists across browser sessions). Code:

public void respond(HttpServletRequest req, HttpServletResponse resp) {
    int expiration = 3600;
    Cookie cookie = new Cookie("TestCookie", "xyz");
    cookie.setDomain("");
    cookie.setVersion(0);
    cookie.setPath("/");
    cookie.setMaxAge(expiration);
    cookie.setSecure(false);
    resp.addCookie(cookie);
}

我在检查IE开发人员工具时看不到此Cookie 。搜索互联网给了我的线索,IE不考虑最大年龄,但只适用于到期。如果这对IE不起作用,那么是否有一种可行的方法来设置持久性cookie的HTTP响应头,以使其适用于IE?

I don't see this cookie being set when I check in IE developer tools. Searching on the internet gave me clues that IE doesn't consider Max-Age, but only works with Expires. If this does not work for IE, then is there a proven way of setting the HTTP response headers for a persistent cookie so that it works for IE?

PS:

我尝试为具有expires属性的cookie创建一个字符串。 IE成功创建它,但它失去了域(默认 - )并显示.com,并将其变成会话cookie而不是持久性cookie。这在所有其他浏览器上也能正常工作。

I tried creating a string for the cookie having expires attribute. IE succeeded in creating it, but it lost the domain (default - "") and showed ".com" and turned it into a session cookie instead of a persistent cookie. This again works fine on all other browsers.

请帮助。
感谢。

Please help. Thanks.

推荐答案

使用IE9,我发现它是 HttpOnly 属性,以便让它在后续帖子上回显cookie值,例如:

Working with IE9, I found that it was the HttpOnly attribute that was required in order to get it to echo the cookie value on subsequent posts, e.g:

Set-Cookie: autologCk1=ABCD; Path=/autolog/; HttpOnly

这篇关于从Java设置持久性cookie在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆