File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Can't read cookie from another page! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can Watch "Can New topic
Author

Can't read cookie from another page!

Li Shangqiang
Greenhorn

Joined: Mar 25, 2001
Posts: 22
<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?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
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:


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't read cookie from another page!
 
Similar Threads
Cookie code...
change cookie value
cookie setDomain problem.
Getting The Value From A Cookie To Use In An If Statement
basic cookie Doubts