This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes sending cookie to another application. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "sending cookie to another application." Watch "sending cookie to another application." New topic
Author

sending cookie to another application.

Ankur Bhutiany
Greenhorn

Joined: Apr 09, 2007
Posts: 3
Hi all, i want to send cookies to another application,so that i can retrieve the same at tht application.I used this code snippet to add and then redirect the response to another application.
Cookie userCookie = new Cookie("loginName", "das");
Cookie pwdCookie = new Cookie("password", "das");
response.addCookie(userCookie);
response.addCookie(pwdCookie);
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location","New URL");

now i tried to retrieve the same using
Cookie[] cookies = req.getKookies();

bt i received onlyone cookie i.e JsessionID cookies added by me are not received .
Anyone can pls help me
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You don't send cookies anywhere.
You leave them on the user's browesr and the browser will include them in any future requests to your domain.

For security reasons, a browser will never send cookies to any domain except for the one which created them. So... if your other URL is not part of the same domain, you will not be able to share cookiess between them.

Also, why are you coding all the headers by hand?
HttpResponse.sendRedirect takes care of all of this for you.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ankur Bhutiany
Greenhorn

Joined: Apr 09, 2007
Posts: 3
Thanks Ben for your reply .It helped me to resolve my doubts.i tried to redirect also but got the same results.So Ben should i conclude that there is no way to share the cookies between two different applications.Anything else you wudlike to suggest on this part
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Ankur Bhutiany:
Thanks Ben for your reply .It helped me to resolve my doubts.i tried to redirect also but got the same results.So Ben should i conclude that there is no way to share the cookies between two different applications.

That is correct.
Cookies are exclusive to the domain in which they were created.

Originally posted by Ankur Bhutiany:
Anything else you wudlike to suggest on this part

Do you have any other questions?
Ankur Bhutiany
Greenhorn

Joined: Apr 09, 2007
Posts: 3
Finally i m able to reslve the problem.We can use the "setPath("/")" method to share the cookies across the application,I tried this and it works fine.

userCookie.setMaxAge(100000);
userCookie.setPath("/");
pwdCookie.setMaxAge(100000);
pwdCookie.setPath("/");
response.addCookie(userCookie);
response.addCookie(pwdCookie);
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: sending cookie to another application.
 
Similar Threads
Using a method to retrieve a cookie
Passing username from Java Application using httpHeader to OBIEE server
how to make remeber me service
Can't read cookie from another page!
How to attach/Detach cookies?