File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question regarding : cookie.getMaxAge()

 
Khushbu Ghodasara
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet that creates and sets the cookie :



and the servlet that gets the cookie :



Here, I'm setting the maximum age for the cookie as 30*60 (30 minutes) but when I reach the second code , where I'm retrieving the cookie info, it gives me the maximum age as -1, that means cookie is not being stored.

I am not able to understand the output. What am I missing here?
[ July 13, 2008: Message edited by: Khushbu Ghodasara ]
 
Dee Brown
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code you state, "Cookie [] cookies = request.getKookies();", so the code cannot compile. Can you supply the actual code that is being used?
 
Khushbu Ghodasara
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the actual code, but here it is not allowed to write getKookie() (read first K as C), due to security reasons, so they asked me to replace C with K in that particular method.
 
Dee Brown
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the api for the cookie class, "The browser returns cookies to the servlet by adding fields to HTTP request headers."

An associated rfc (2109) states:

4.3.4 Sending Cookies to the Origin Server

When it sends a request to an origin server, the user agent sends a
Cookie request header to the origin server...

The syntax for the header is:

cookie = "Cookie:" cookie-version
1*((";" | ",") cookie-value)
cookie-value = NAME "=" VALUE [";" path] [";" domain]
cookie-version = "$Version" "=" value
NAME = attr
VALUE = value
path = "$Path" "=" value
domain = "$Domain" "=" value

It would therefore appear the maxAge value you are retrieving is one the container supplies when it instantiates a cookie it receives from the client. Since the setting of maxAge is the setting of a value that is used by the client, the fact that the "-1" is retrieved is not all that important.

You can verify that the maxAge is not in the request header using the Live HttpHeaders plugin/addon in the Firefox browser.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic