Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem related to cookies

 
shveta gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the servlet specification it is specified that session tracking cookie must be JSESSIONID...
but in HFSJ (CH-6 pg 248)they have specified that one can tell a cookie to stay alive even after the browser shuts down and in the example they have written

Set-Cookie:username=x

and

Cookie:username=x.

Kindly solve this problem as I am getting confused that is there a restriction on the name of the cookie or not???
Thanks in advance.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes you can do that by calling the setMaxAge(), but when you call getMaxAge() on the the JSESSIONID cookie, you will get the value -1, which means, it will disappear when the user closes the browser.

I hope that i made myself clear ...
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shveta,


public void Cookie.setMaxAge(int expiry)
Specifies the maximum age of the cookie in seconds before it expires. A
negative value indicates the default, that the cookie should expire when
the browser exits. A zero value tells the browser to delete the cookie
immediately.




With Regards,
 
shveta gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i wanted to know that whether there is a cookie naming restriction or not.....???
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shveta:

Actually i wanted to know that whether there is a cookie naming restriction or not.....???



No, there is no naming restriction to cookies. You can name it like "123". But to access it from the JSP, you have to do like:

In servlet:


In JSP:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic