Meaningless Drivel is fun!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes why cookies getMaxAge method return -1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "why cookies getMaxAge method return -1" Watch "why cookies getMaxAge method return -1" New topic
Author

why cookies getMaxAge method return -1

Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
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

Joined: Mar 27, 2006
Posts: 245
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.


Vikrant Pandit
William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
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.


Java is better and better, yet bitter and bitter.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
Thanks to everyone
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why cookies getMaxAge method return -1
 
Similar Threads
Question regarding : cookie.getMaxAge()
cookie.getMaxage() question
cookie.getMaxAge reads -1
Cookie.getMaxAge, encodeRedirectURL
cookie.getMaxAge