Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sending cookie to another application.  RSS feed

 
Ankur Bhutiany
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankur Bhutiany
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!