This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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

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
in servlet2 i try to get cookie max age as
but cookie.getMaxAge() return -1
i dont not understand why.
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é

Joined: Nov 24, 2005
Posts: 14688

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
I agree. Here's the link:
subject: why cookies getMaxAge method return -1
It's not a secret anymore!