• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Where do all the cookies go?

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Allen Williams
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic