Invalid content length for response text with umlaut

There is a problem with the umlaut. I get a description on request:

@RequestMapping(value = "/description", method = RequestMethod.POST, consumes = "application/json", produces = "text/plain;charset=UTF-8")
    @ResponseBody
    private String getDescription() {        

        return "ärchik";
    }

on frontend response.responseText cannot type the last letter response.responseText = "ärchi"

I found that the problem is in the wrong Content-Length: 7 if Content-Length: 8 is set, then it will work and return the full description of "ärchik"

But I do not understand why 8?

"ärchik".getBytes("UTF-8").length = 7

Answer Headers

Cache-Control: Be sure to double-check

Content-Length: 7

Content-Type: text / regular; encoding = UTF-8

Date: Mon, Apr 14, 2014 09:08:26 GMT

Server: Apache-coyote / 1.1

+4
source share
3 answers

, , .

, , , , 'ä' , . , precomposed U + 00E4 (UTF-8: c3 a4), 'a' ( ASCII U + 0061), combining diaresis U + 0308, 61 cc 88. Unicode, , , NFD.

, , , (, , NFC-) .

+4

((

//set content-length = 7    
chain.doFilter(request, wrappedResponse); 
byte[] bytes = wrappedResponse.getByteArray(); 
String out = new String(bytes, utf8Charset);//7bytes 
out = Normalizer.normalize(out , Normalizer.Form.NFD);//8bytes
+1

spring / comment tomcat is right.

  response.responseText is Ajax response Object?

I assume: the encoding of the js file is not UTF-8; some function does not work for UTF-8 javascript.

0
source

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


All Articles