Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 870
  • Last Modified:

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
0
jdean4
Asked:
jdean4
  • 2
1 Solution
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now