JSP: setting special characters for a cookie value

I've noticed that with Tomcat 5.5.12 (and other JSP engines?), if I save special characters in a cookie (with cookie.setValue()), it doesn't work. More specifically, when I load a page later on and attempt to retrieve one of those cookie values, I see nothing. Note that cookie values that do not contain space, comma, quote, or semicolon work fine. So what's the best way to save cookie values if they have special characters? Do I have to use JavaScript's escape and unescape functions? I'd prefer to keep my solution within JSP, but if using JavaScript is the preferred solution, then so be it.

This is my first experts exchange question, so I'm not sure how I'll get an answer. Please advise and send your answer to <mail removed by Venabili>
Thanks,
John
jdean4Asked:
Who is Participating?
 
bloodredsunCommented:
use java.net.UrlEncoder.encode( "a String" , "UTF-8") and then the corresponding decoder object java.net.UrlDencoder.decode( "a String" , "UTF-8")
0
 
bloodredsunCommented:
And by the way john, we try to keep the answers posted on EE so that it is searchable for future use. Also, I'll get one of the PE's to remove your email (unless of course you like lots of spam from spam crawlers)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.