• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to test cookies in localhost

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have problem with cookies. I have webapplications in localhost. I need to send cookies from one app to other. my porblem is they are not getting passed from one app to other, Though they will pass because these two apps share domain in real time scenario.
Can any one help me out in testing these croos app cookies in localhost?
Thanks for your help in advance..
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you calling the setPath() method of the cookie when you write it? To make the cookie available to other apps you need to set this to the root path by using

Also, check that the cookie is being sent to your browser by viewing the cookies. (I find FireFox is excellent for this.)

Steve
[ October 28, 2005: Message edited by: Steve McCann ]
 
Shiva Battula
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve.
I tried as follows in site 1

Cookie targCokk = new Cookie("xxx_ID","APP_1");
response.addCookie( targCokk );
targCokk.setPath("/");
response.sendRedirect("http://localhost:8080/App2Log/login");

In site 2 action, I tried to retrive cookies set by site 1 as follows.
Cookie[] cookieArr = request.getkookies();
int i = 0;
while( cookieArr!=null && i < cookieArr.length ){
Cookie cokieObj = cookieArr[i];
System.out.println( cokieObj.getName()+"=" + cokieObj.getValue() );
i++;
}

I enabled cookies on my browser..
But Cookies from site 1 are not getting passed to site 2.
Please..Please..Please help me on this..
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your code you have added the cookie to the response before setting the path. Change your code to this:


Steve
 
Shiva Battula
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve.
Its working fine now after your suggestion..
Sivasankar
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent! Have a good weekend.

Steve
 
Shiva Battula
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks..same to you..
Sivasankar
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Steve McCann
Are you calling the setPath() method of the cookie when you write it? To make the cookie available to other apps you need to set this to the root path by using cookie.setPath("/");



What do u mean by root path?

cookie.setPath("/");

Does it mean root of the second application. I tried with second application name in setpath() method like

cookie.setPath("/AppTwo");

I got the expected results. Whats the difference between both of these.


Originally posted by Steve McCann
check that the cookie is being sent to your browser by viewing the cookies. (I find FireFox is excellent for this.)



You mean to print the cookies to the browser window like this
<% out.print(cookie.getName()+" = " + cookie.getValue() ); %>
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any takers
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vishnu

What do u mean by root path?
cookie.setPath("/");


I guess I meant the root of all the webapps on the server, so that the cookie can be viewed by all the applications.

You mean to print the cookies to the browser window like this
<% out.print(cookie.getName()+" = " + cookie.getValue() ); %>


No, I meant to view the cookies using the brower rather than using the code. By using code you need the cookie to be seen by the app, which was the problem in the first place.

Hope this helps
Steve
[ October 31, 2005: Message edited by: Steve McCann ]
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic