Reputation: 4875
I am trying to HTML-Encode a string with jQuery, but I can't seem to find the right encoding format.
What I got is a String like Ütest.docx. The server doesn't handle special characters very well so that I get a FileNotFoundException from Java (I have no way of editing the server itself).
Now, I tried around and found out that the URL works when I replace Ü with %DC. Now I tought this is called HTML Encoding, googled a bit but I always get results saying something about URL-Encoding. I checked that, and it seems like this isn't the right encoding, because Ü is beeing encoded to %C3%9C, which doesn't work for the server.
Now, which encoding is it, that would encode Ü to %DC? And is there a function in javascript or jQuery that would to the encoding for me?
Thanks for any help, I've been trying to find out which encoding I need for an hour now, but no luck.
Upvotes: 0
Views: 608
Reputation: 140230
They are both URL encoding, just that the UTF-8 one is a newer standard.
If you are using Tomcat, you can use just encodeURIComponent()
which uses UTF-8
and works when you set the Tomcat connector URIEncoding attribute to <connector URIEncoding="UTF-8" ...>
If that's not ok, you can use this:
function uriEncodeLegacy( str ) {
return escape(str.replace( /[\u0100-\uFFFF]/g, ""));
}
uriEncodeLegacy("Ü") //%DC
However UTF-8 is recommended, otherwise you cannot even support the €
character for example.
Upvotes: 1