0

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.

4
  • Are you looking for the escape("string") unescape("escapedString") jsfiddle.net/J5DxR Commented Apr 4, 2013 at 10:22
  • @Bondye While in jsfiddle escape works properly, on my page it still gets encoded to %C3%9C Commented Apr 4, 2013 at 10:33
  • @Ahatius if you are using a normal form submit, then you can't affect it by javascript. If you are making the request with ajax, you can and it should work. Commented Apr 4, 2013 at 11:57
  • @Esailija Well, it's not bound to a form. It's a link to an attachment (PDF, or DOC or whatever). Problem is that the application doesn't accept ü (and äö....), which is why I'm trying to encode it in a way the server can handle it. Commented Apr 4, 2013 at 12:21

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

It is a Tomcat server running behind. Where would I have edit the connector? web.xml?
@Ahatius It's not an application setting but a server setting found in server.xml. Find your connector (by default the one with port=8080)
Unfortunately there doesn't seem to be a server.xml (it's a Java application using tomcat).
@Ahatius it's a server setting it's not on the application but on the tomcat configuration files themselves. If you are using eclipse for example during development, it would be in the servers project. If you are on production, it's found under tomcat-server-directory/conf/server.xml
It's not a standalone tomcat server, it's integrated in the java application. I trough the whole application directory, but it looks like there is no tomcat, maybe it's configured internally. Only thing I can find is a web.xml in a WEB-INF directory.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.