• 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

A doubt in Cookie

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was trying out Cookie example from Session Mgmt chapter of HSFJ.
What I did was, created a new cookie with key=username and value=xyz. I also did a setMaxAge(5*60); on that cookie object and added that in response.
After sending the response, I checked in browser(firefox 3.0) for the cookie. The cookie was present with expiry time as expected i.e 5 minutes after current time.
Now, I made a another request to some other servlet where I checked the maxAge for that old cookie (i.e "username"). Surprisingly, getMaxAge() returned -1. I realized that this can be because the browser is sending the cookie in Header as "cookie:username=xyz" which doesn't contain any info about the max age. So, it is giving the max age by default as -1 to that cookie.
What I wanted to know is, if there is any way I can find out the original maxAge of the cookie which I had set while creating it in previous response?

Hope.. my doubt is clear.

Thanks
Sumit
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the timeout is maintained by the client side, and not shared with the server. Why do you want to get the timeout?
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sumit Jindal:
What I wanted to know is, if there is any way I can find out the original maxAge of the cookie which I had set while creating it in previous response?



No, and more importantly:

Never trust data from the client/browser.

Never ever.

It is much better to set the cookie to a nonce value, and use the nonce as the key to a HashMap on your server/servlet side
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic