wood burning stoves 2.0*
The moose likes JSP and the fly likes Cross-Domain Cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Cross-Domain Cookies" Watch "Cross-Domain Cookies" New topic
Author

Cross-Domain Cookies

sundaresan ganapathy
Greenhorn

Joined: Oct 08, 2008
Posts: 23
Hi All,
I am trying to have two webapps such as WebApp1 and WebApp2.

1. I am setting one cookie in WebApp1 in the HttpResponse.
2. How to read the same cookie from HttpRequest at WebApp2?

I know it sounds weired b'coz cookies are specific to websites, we cant access it from different webapp. But i heard of CROSS-DOMAIN cookies which can be shared across multiple webapps.How to implement this requirement using CROSS-DOMAIN cookies.

Please post your suggestions on this....

Note: I am trying this at J2ee webapps

Thanks In Advance,
Sundar
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Are both web apps running on the same (sub) domain? If so, you can set the cookie path and domain; check the Cookie.setPath and Cookie.setDomain methods.

And no, HTTP cookies do not work across domains.
sundaresan ganapathy
Greenhorn

Joined: Oct 08, 2008
Posts: 23
Hi lester,
I can implement this Domain and SubDomain, can you please provide more clarity on this???

Thanks,
Sundar
sundaresan ganapathy
Greenhorn

Joined: Oct 08, 2008
Posts: 23
I meant, can you please add more clarity on configuration part, how to create/configure domain and subdomain in j2ee environment???

Thanks
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
There isn't anything to configure, really, except for using the Cookie.setDomain method for any cookies you create. If you have web apps at a.domain.com and b.domain.com, then setDomain("domain.com") should make the cookie visible to both web apps (not sure about the details, play around to see what works). Reading the cookie spec will probably be helpful, too.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

i found it really helpful using firefox, and using the "delete single cookies" option to scroll through my cookies to see what the values were
sundaresan ganapathy
Greenhorn

Joined: Oct 08, 2008
Posts: 23
Hi,
I tried having two webapps
(1) WebApp.domain.com ==> here i add cookie in respose as follows

Cookie cookie = new Cookie("namedCookie","test");
cookie.setDomain(".domain.com");
response.addCookie(cookie);

(2)WebApp1.domain.com==>Here i tried to access the cookie as follows, but cant able to access

Cookie[]cks = request.getCookies();
for(int i=0;i<cks.length;i++){
out.print("cookie found"+cks[i].getValue());

}

Any idea on this?>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

sundaresan ganapathy wrote: it sounds weired b'coz cookies

Please use real words when posting to the forums. Abbreviations such as "b'coz" in place of "because" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please click this link ⇒ UseRealWords for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cross-Domain Cookies