UTF-8 URL decoding / coding difference between Java and JS / AS3 (bug !?)

I have a problem decrypting the URL of a UTF-8 string in Java, which is encoded either using Javascript or ActionScript 3. I installed a test case as follows:

This line contains Produktgröße

When I encode JS / AS3, I get the following line:

escape('Produktgröße')

Produktgr% F6% DFe

When I unescape this with JS, I don't get any changes

unescape('Produktgr%F6%DFe')

Produktgr% F6% DFe

So, by this, I assume that JS is not encoding the string correctly ??

Next jsp creates this outupt

<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%=(URLDecoder.decode("Produktgr%F6%DFe","UTF-8"))%><br/>
<%=(URLEncoder.encode("Produktgröße","UTF-8"))%><br/>
<%=(URLEncoder.encode("Produktgröße"))%><br/>
<%=(URLDecoder.decode(URLEncoder.encode("Produktgröße")))%><br/>
<%=(URLDecoder.decode(URLEncoder.encode("Produktgröße"),"UTF-8"))%><br/>

Produktgr? E

Produktgr% C3% B6% C3% 9Fe

Produktgr% C3% B6% C3% 9Fe

Produktgröße

Produktgröße

Any idea why I have such a mismatch with languages ​​and why JS / AS3 doesn't behave as I expect?

Thank.

+5
3

escape - Unicode. encodeURI encodeURIComponent, , , , .

+10

Javascript - URL-, , Latin-1 charset. Java URL, UTF-8.

URL /, . , ASCII, ( %28. , , ASCII ( 7 ).

+1

... JQuery Ajax :

return $.ajax({
        url: '/author!getAuthorContent.action',
        type: 'GET',
        data : {author:name, 'content_type': ct || 'all', 'start': start || 0}
    });

'name' - , , Jérôme-Serrano

- , JS/JQuery , , Java BackEnd...

:

  • JS var econded = encodeURIComponent(name);
  • Java, String decoded = java.net.URLDecoder.decode(econded ,"UTF-8");

some memories: http://www.programering.com/a/MjN2ADOwATg.html http://www.theerrormessage.com/2013/10/weird-characters-transmitted-to-and-from-server-through-jquery- ajax-call /

+1
source

All Articles