共享子域cookie
我有一个域“www.foo.com”,我想创建子域“test.foo.com”。 为了合并这 2 个域以仅共享一个 cookie,我将 cookie 设置为如下所示:
Cookie cookie = new Cookie("myCookie", "myValue");
cookie.setMaxAge(60 * 60);
cookie.setDomain(".foo.com");
因此从现在开始将只有一个 cookie:“foo.com”,并且这些值将保存在同一个 cookie 上。 问题是对于老用户来说,对于他们来说会有两个cookie('www.foo.com'和'foo.com'),我怎样才能将这两个cookie合并为一个?
另一件事是,来自“test.foo.com”的用户最终将访问“www.foo.com”,反之亦然。
I have a domain 'www.foo.com' and I want to create sub domain 'test.foo.com'.
In order to combine those 2 domains to share only one cookie I set the cookie to be like that:
Cookie cookie = new Cookie("myCookie", "myValue");
cookie.setMaxAge(60 * 60);
cookie.setDomain(".foo.com");
So from now on there will be only one cookie: 'foo.com' and the values will be save on the same cookie.
The problem is for old users, for them there will be two cookies ('www.foo.com' and 'foo.com'), how can i merge those two cookies to one??
One more thing, users from 'test.foo.com' eventually will visit 'www.foo.com' and vise versa.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 http servlet 请求中获取旧的 cookie,然后将其最大期限设置为 0。这将触发客户端删除它(在其自己的时间内,通常是立即)。另请参阅有关 Cookie 的 Javadoc。
您需要解析您的 cookie 并搜索您想要删除的 cookie。像这样的东西:
Get the old cookie from the http servlet request, then set its max age to 0. That will trigger the client side to get rid of it (in its own time, normally right away). Also, see the Javadoc on Cookie.
You will need to parse through your cookies and search for the one you are trying to get rid of. Something like this: