• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Question regarding : cookie.getMaxAge()

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic