• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing Cookies

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing some code to write a cookie.. but its not happening. Can someone give me example of code to write a cookie. I even created the cookie and then added it to the response.. but nothing. Any help is apprecaited.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create a cookie that stores a user name retrieved from a request parameter:To get all the cookie from the client and print them to the screen:
By the way, if you are curious about the getKookies() method in the above code, it is that way because the bulletin board security would not let me type in the correct method name (replace the K with a C).
[ January 03, 2005: Message edited by: Paul Bourdeaux ]
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do these need to happen in a Servlet or can they happen in a jsp page as well?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do the same thing from a JSP page.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it from a jsp with scripting... just include the same code inside the <% and >% tags. JSPs have both a request and response implicit object. You can also get (but not set) cookies VERY easily using EL. EL has an implicit object called cookie that is a map of cookie names/values. ${cookie.username.value} will return the value for the cookie named "username".

By the way, I personally wouldn't set any cookies from a jsp anyway...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic