wood burning stoves 2.0*
The moose likes Servlets and the fly likes Persistent Cookies with Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Persistent Cookies with Servlets" Watch "Persistent Cookies with Servlets" New topic
Author

Persistent Cookies with Servlets

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
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

Joined: Feb 07, 2004
Posts: 472

I believe cookie spec doesn't specify that client should transfer cookie expiration time. Cookie: http header has very simple format as name=value,


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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)


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

When you do so, remember to use web site which sets a cookie, for example saloon.javaranch.com
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 02, 2007
Posts: 39
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persistent Cookies with Servlets