• Post Reply Bookmark Topic Watch Topic
  • New Topic

Whats the best way to encode in JavaScript and Decode in Java code?  RSS feed

 
Neel Priyadarshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am maintaining a code in which users response is encoded in JavaScript using escape and then decoded in Java Code using URLDecoder.decode.
It works perfectly but recently it starts breaking for Smart Quotes like “, ”.

I see that escape converts smart quote like “test” in %u201Ctest%u201D.
However, when I try decoding it as

or

it throws the exception
%u201C exception java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern

I did some google and advise was to use encodeURI or encodeURIComponent.

If I use these, “test” gets converted to %E2%80%9Ctest%E2%80%9D but now when I use UrlDecoder it gives me
ôtestö.

Please advise what is the best way to do encode-decode when you do encoding in Java Script and decoding in Java.

Neel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!