【问题标题】:Cookies are not retained when IE is restarted重新启动 IE 时不保留 Cookie
【发布时间】:2013-06-26 18:25:14
【问题描述】:

我尝试了一个示例 Web 应用程序来存储和检索 cookie。

HttpServletResponse response = (HttpServletResponse)Executions.getCurrent().getNativeResponse();
Cookie [] cookies = ((HttpServletRequest)Executions.getCurrent().getNativeRequest()).getCookies();

我在响应中添加了一些 cookie,并且可以检索它们。

我用的是IE8,有两种情况-

  1. 我打开了一个 IE 浏览器(假设 A)。我在另一个 IE 浏览器(假设 B)中启动了应用程序并设置了 cookie 值。现在我关闭 B 并打开一个(另一个假设 C),我可以从 Cookie 中检索值,因为 A 仍然打开。 效果很好。

  2. 如果我现在打开一个新浏览器(假设 A)设置 cookie。我关闭 A 并打开另一个(假设 B)。在这里我无法从 cookie 中检索值,因为没有打开其他浏览器...

寻找解决此问题的建议,以始终检索值,而不管浏览器打开/关闭。

【问题讨论】:

    标签: internet-explorer cookies


    【解决方案1】:

    默认情况下,cookie 会在会话(通常是浏览器的窗口)到期时到期。

    您需要在将来设置到期日期。大概是setMaxAge():

    http://www.tutorialspoint.com/servlets/servlets-cookies-handling.htm

    【讨论】:

    • 丹尼斯,您的解决方案正在运行...谢谢。我早些时候在我的应用程序中尝试过这个,当时它没有工作......现在它可以在我尝试过的示例和应用程序中工作。非常感谢
    猜你喜欢
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多