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 JSP and the fly likes Unable to set cookies with jsp 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 » Java » JSP
Bookmark "Unable to set cookies with jsp" Watch "Unable to set cookies with jsp" New topic

Unable to set cookies with jsp

Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
If I for example use the following code in a JSP page:
Cookie cookie = new Cookie("t", "v");
cookie.setMaxAge(60 * 60); //1 h in seconds
Will I be able to access a cookie named "t" next time I visit this site (if it's within an hour)? Or do I have to do something to actually set the cookie? I can't get it to work..
Please help...:-) //Tom
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Do you need to specify the domain and/or the path for the cookie? I'm not sure if the response will take care of that when you call addCookie(). Otherwise, I don't see anything wrong with this. (Sorry, I'm not much help here -- I haven't had too much experience with cookies in JSP.)

I agree. Here's the link:
subject: Unable to set cookies with jsp
Similar Threads
setMaxAge on cookie using JSTL
Setting Cookie
Cookies not getting reset in Netscape 4.72!!! URGENT!!!
Confusion about session destruction
Not able to set cookies