• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why cookies getMaxAge method return -1

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in servlet1 i have set cookie max age as
cookie.setMaxAge(30*60)
in servlet2 i try to get cookie max age as
cookie.getMaxAge()
but cookie.getMaxAge() return -1
i dont not understand why.
Thanks.
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess your browser is not returning the age of the cookie
Some browsers might just return name-value pair but not the age of the cookie correctly

Try to see the age of the cookie on the browser.
 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes gowher, I have the same problem.
I agree with Vivek, you can setMaxAge() to the cookie and send it to browser, but when you get the cookie from the browser, the information of the cookie is not complete(maxAge lost..). So you cannot get correct maxAge.

But when you check the cookie information in the browser(i use FF), you can see the correct answer there.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SRV4.6
Typically, the only information that the client sends back as part of a cookie is the cookie name and the cookie value. Other cookie attributes that can be set when the cookie is sent to the browser, such as comments, are not typically returned.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to everyone
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic