my dog learned polymorphism*
The moose likes JSP and the fly likes writing a cookie to the disk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "writing a cookie to the disk" Watch "writing a cookie to the disk" New topic
Author

writing a cookie to the disk

Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
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

Joined: Jul 28, 2001
Posts: 260
it will


Asher Tarnopolski
SCJP,SCWCD
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
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

Joined: Jul 03, 2002
Posts: 319
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

Joined: Jul 03, 2002
Posts: 319
yeap. setMaxAge() works out and I think that should be the standard way of doing it.
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
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

Joined: Jul 03, 2002
Posts: 319
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: writing a cookie to the disk