This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing a cookie to the disk

 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Will the following code in a JSP page do to write a cookie to the disk?

i.e., when I display this page in the browser, will it create a cookiew file in the hard disk? Or should I do more to achieve this?
-thanks
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it will
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so, since the default Cookie lifetime is while the browser is running.
You will have to setMaxAge
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO! For some reason it doesn't. Then i have added another cookie like this,

The "never" can also be replaced by a valid date.
thanks
sudharsan
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeap. setMaxAge() works out and I think that should be the standard way of doing it.
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setMaxAge sets the cookie life time period.
when created the default cookie's MaxAge is set to a negative value, which means the cookie will be deleted when the browser session will be closed.
so, you don't need to run setMaxAge to set a cookie, but you have to run it to manage its life time.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah! I knew this. My question was 'How to make a cookie permanent across sessions?'. And I've got the answer!
thanks
[ December 25, 2002: Message edited by: Sudharsan G'rajan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic