aspose file tools*
The moose likes Servlets and the fly likes Where do all the cookies go? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Where do all the cookies go?" Watch "Where do all the cookies go?" New topic
Author

Where do all the cookies go?

Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
Not sure whether this goes here or a different forum, but here goes:

Could someone please tell me how cookies are scoped and managed? I have a web application, implemented with Tomcat, and in some parts of the application I can get cookies, and in others not. The header HOST value is the same (I've printed it out), so I don't know how to get at these cookies.

What I'm trying to do is implement an autologin type feature. When the user logs on manually (via a page like "http://host.com/login.jsp"), the user is validated via a database lookup in a servlet and userid/password cookies are stored (by this servlet, with a uri in the jsp's form like "/appname/ManualLogin"). The login.jsp page populates the form fields (${cookie.userid.value}) from the cookies with no problem. At logon, a user bean is stored. When the user goes to an internal page (like "http://host.com/UserData/userid/home.jsp"), if the user bean is not set, he will be redirected to an autologin servlet (from the jsp page, this is <jsp:forward page="/AutoLogin" />. This servlet attempts to get the userid/password cookies from the request. The autologin servlet does not see the cookies.

Any ideas about what's happening to these cookies and how to get to them from the autologin servlet?

TIA,
anw


-------<br />Thanks & regards,<br />anw
li bei
Greenhorn

Joined: Jul 22, 2007
Posts: 20
Cookie cookie=new Cookie(key,value);
then,set the scope via cookie.setPath("path");
if you cookie.setPath("/") , then this cookie is available anywhere in the application.

I am sorry that my English is poor,if there is something wrong with my words, please tell me .Thank you!
[ July 22, 2007: Message edited by: li bei ]

I am sorry that my English is poor.If there is something wrong with my words,please tell me .Thank you very much.
Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
You're English is fine, and thank you! I found it myself, and was just fixing to post this:

OK, evidently where I was setting the cookies grabbed a default path for the cookies. When I set the cookies and explicitly set a path of "/" (Cookie.setPath("/")), they are all available.

Thanks to anyone who may have looked at this.

Regards,
Allen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where do all the cookies go?