• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Persistent Cookies with Servlets

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic