Encoding problem between jQuery and Java

My encoding is set to ISO-8859-1.

I am making an AJAX call using jQuery.ajaxfor a servlet. The URL (after it was serialized by jQuery) is as follows:

https://myurl.com/countryAndProvinceCodeServlet?action=getProvinces&label=%C3%85land+Islands

The actual value of the label Åland Islands. When it comes to the servlet, the value I get is the following:

Ã\u0085land Islands

But that is not what I want. I would like it to be decoded before Åland Islands. I tried a lot of things (setting scriptCharset, trying to convert a string using getBytes(), but nothing works).

+3
source share
2 answers

Servlet, , , ​​ . .

- , , , Servlet, UTF-8, ISO-8859-1. ( ISO-8859-1, Windows 1252, , , ISO-8859-1!)

, . Tomcat server.xml.

, , , / . , ISO-8859-1 , , , UTF-8, ISO-8859-1, , UTF-8. , - UTF-8, ...

+6
, . , URI, URI . GET HttpServletRequest#getQueryString(). URL- UTF-8 , String URLDecoder#decode().
for (String parameter : request.getQueryString().split("&")) {
    String[] pair = parameter.split("=");
    String name = URLDecoder.decode(pair[0], "UTF-8");
    String value = URLDecoder.decode(pair[1], "UTF-8");
    // ...
}

, , , .

+3

Source: https://habr.com/ru/post/1771584/


All Articles