• 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

Can't read cookie from another page!

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<p>I'm using cookie to store info, and it works in saving and retreiving cookie in the same page, but when i try to retrieve the cookie from another page, i can't get the cookie.
<p>
The code is like this:
<pre>
String cookieName2 = "cfai.UserID";
Cookie newCookie = new Cookie(cookieName2, String.valueOf(userID));
newCookie.setDomain("localhost:8080");
newCookie.setMaxAge(3600 * 24 * 30 * 365); // response.addCookie(newCookie);
...
in another page:
Cookie[] cookies = request.getCookies();
for (int i=0; i<cookies.length; i++) {
System.out.println(cookies[i].getName());
}
</pre>
My app server is Tomcat3.1
Who can give me answer?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The javadocs for cookie say to follow RFC2109 for setDomain.
RFC2109 says "An explicitly specified domain must always start with a dot" - also it does not mention use of a port. Try
setDomain(".localhost");
Bill
------------------
author of:
reply
    Bookmark Topic Watch Topic
  • New Topic