java 在java中的子域之间共享Cookie?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4538484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sharing Cookies Between Sub Domains in java?
提问by Mahmoud Saleh
greetings all i have some cookies stored in http://sub1.myserver.comand i want to be able to see them in http://myserver.comany ideas how to do that ?
问候所有我在http://sub1.myserver.com 中存储了一些 cookie ,我希望能够在http://myserver.com 中看到它们有 什么想法怎么做吗?
回答by Mahmoud Saleh
I was able to do it using the following code:
我能够使用以下代码来做到这一点:
Cookie cookie = new Cookie("myCookie", "myValue");
cookie.setMaxAge(60 * 60);
cookie.setDomain(".myserver.com");
回答by cdhowie
When you set the cookies from sub1.myserver.com, you must specify a domain of "myserver.com" -- this will instruct the browser to send the cookies to myserver.com and all subdomains.
当您从 sub1.myserver.com 设置 cookie 时,您必须指定一个域“myserver.com”——这将指示浏览器将 cookie 发送到 myserver.com 和所有子域。