This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Persistent Cookies with Servlets

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read the following quote in a book...
....once cookie is created, you have access only to its name and value. You can�t access cookie's maximum age, because the header contains only the name and value information.

Is this correct?
But, I did see a method called getMaxAge().
Also, I wrote a test servlet, shown below:


It displays the session age as -1. But, while this cookie was created it was set as cookie.setMaxAge(30*60);

Any help shall be highly appreciated.

Thanks,
Reema
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe cookie spec doesn't specify that client should transfer cookie expiration time. Cookie: http header has very simple format as name=value,
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to know exactly what gets sent, download the LiveHttpHeaders plugin for Firefox and hit your test servlet.
You will be able to see all of the headers (cookies included)
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you do so, remember to use web site which sets a cookie, for example saloon.javaranch.com
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting.

Ben,
I don't really need to download anything, using FireFox I can go to Tools->Options->Privacy->Cookies->View Cookies, I get to know everything about a cookie. So, why would I need to download xyz s/w?


I have a very simple Q- Y
You can�t access cookie's maximum age, because the header contains only the name and value information
Is this correct?
Loking at the cookie data, I belive it'svery apt, then wat is the getMaxAge(
) doing in the Cookie class?

Thanks,
Reema
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reema Patel:
Thanks for posting.

Ben,
I don't really need to download anything, using FireFox I can go to Tools->Options->Privacy->Cookies->View Cookies, I get to know everything about a cookie. So, why would I need to download xyz s/w?



Viewing the headers with a tool like LiveHttpHeaders or tcpflow shows you exactly what is being passed between the client and server.
 
William Janssen
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you set the maximum age of a cookie, with setmaxAge(int sec), the getMaxAge will always return -1 which is the default (for some cookies it can be confiugred within the appserver the application is executed). The scope is only the cookie object on which it is set.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic