来自IE中的servlet的持久性cookie [英] Persistent cookies from a servlet in IE

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

问题描述

我有一个从servlet生成的cookie,我想永久 - 也就是设置cookie,关闭IE,启动它,仍然能够读取cookie。我使用的代码如下:

I have a cookie which is generated from a servlet and that I would like to be persistent - that is, set the cookie, close down IE, start it back up, and still be able to read the cookie. The code that I'm using is the following:

HttpServletResponse response = 
    (HttpServletResponse) FacesContext.getCurrentInstance()
    .getExternalContext().getResponse();

Cookie cookie = new Cookie("someKey", "someValue");
cookie.setMaxAge(7 * 24 * 60 * 60);
response.addCookie(cookie);

这在firefox中工作得很好,但在IE 6/7中,浏览器重新启动。我已经检查了我可以在我的设置,我想到的一切,但不能弄清楚会导致cookie被删除。据我所知,调用带有正数的setMaxAge使得cookie持久化。任何想法为什么会出错?

This works great in firefox, but in IE 6/7, the cookie is not saved between browser restarts. I've checked everything that I can think of in my settings, but can't figure out what would be causing the cookie to be deleted. As far as I know, calling setMaxAge with a positive number makes the cookie persistent. Any ideas why this would be going wrong?

编辑

,使用Olaf建议的更多信息技巧,cookie尝试设置为会话cookie,而不是持久性cookie;最大年龄设置为会话结束。所以它似乎不是最大年龄被设置为IE - 我已经验证,在Firefox中,最大年龄设置正确。我仍然不知道发生了什么。

I have verified, using the more info trick suggested by Olaf, that the cookie is attempting to be set as a session cookie, not a persistent cookie; the max age is set to "end of session". So it doesn't seem like the max age is being set for IE - I have verified that in Firefox, the max age is set correctly. I still have no idea what's going on.

推荐答案

我不知道Java或servlet,但IE只会持久一个cookie if它有一个到期日期,设置最大年龄不足,IE将继续将其视为会话Cookie。

I know nothing of Java or servlets, but IE will only persist a cookie if it has an Expires date, setting max-age is not sufficient, IE will continue to treat it as a session cookie.

这篇关于来自IE中的servlet的持久性cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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