We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


JSP: setting special characters for a cookie value

jdean4 asked
Medium Priority
Last Modified: 2008-02-01
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>
Watch Question

Top Expert 2006
use java.net.UrlEncoder.encode( "a String" , "UTF-8") and then the corresponding decoder object java.net.UrlDencoder.decode( "a String" , "UTF-8")

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2006

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)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.