Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cross-Domain Cookies

 
sundaresan ganapathy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi lester,
I can implement this Domain and SubDomain, can you please provide more clarity on this???

Thanks,
Sundar
 
sundaresan ganapathy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic