This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem related to cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem related to cookies" Watch "Problem related to cookies" New topic
Author

Problem related to cookies

shveta gupta
Greenhorn

Joined: Jul 12, 2006
Posts: 4
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

Joined: Mar 08, 2007
Posts: 1585
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 ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
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,


cmbhatt
shveta gupta
Greenhorn

Joined: Jul 12, 2006
Posts: 4
Actually i wanted to know that whether there is a cookie naming restriction or not.....???
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
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:
 
wood burning stoves
 
subject: Problem related to cookies
 
Similar Threads
Generate cookie for locking
how do i use the cookies??
Session Doubt?
Variable caching in JSP in Jboss server
Session management in Servlets