| Author |
Cookie persistance across packages?
|
Chad Clites
Ranch Hand
Joined: Aug 16, 2005
Posts: 134
|
|
I have an app that checks for a cookie, and if it doesn't exist, asks for log-in information, and sets a cookie once login information is verified. Nothing earth shattering there, and that works perfectly. The cookie is set. Once the cookie is set, the servlet forwards the response to a servlet in another package. I am trying to use the following code to retrieve the cookie: If I try to do getC00kies from a different package, cookieArray is null. I know the code works though because if I use it from the same package, then I can get the cookies. I have been reading as many different threads I can find on the topic, but I can't find any that specifically deal with multiple packages, and I am guessing that the fact that I am not able to get the cookies has to do with the fact it is from a different package. Is that a correct assumption? I have checked Sun's documentation, and I can not seem to find what I have to do to set the cookie to make it available across packages. EDIT: Now that I asked, I apparently need to set the domain correctly for each cookie.... [ August 23, 2006: Message edited by: Bear Bibeault ] [ August 23, 2006: Message edited by: Chad Clites ]
|
 |
Chad Clites
Ranch Hand
Joined: Aug 16, 2005
Posts: 134
|
|
I apologize for the double post, but I figured out my problem. My assumption about setting the Domain was correct; however, many threads I looked at were giving incorrect advice. Since I am testing in my development server, I knew my domain was localhost. Many of the threads I looked at recommended setting domain like this: userCookie.setDomain("localhost"); or userCookie1.setDomain("http//localhost:8080"); Unfortunately, that advice seems to be incorrect. From the Cookie documentation:
The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com) and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone (for example, www.foo.com, but not a.b.foo.com).
So it turns out that the correct domain for my cookie was: userCookie1.setDomain(".localhost.Auth_New"); And now it works perfectly. [ August 23, 2006: Message edited by: Chad Clites ]
|
 |
 |
|
|
subject: Cookie persistance across packages?
|
|
|