UTF-8 encoding problem with servlet and apache HttpClient UTF-8 encoding problem with servlet and apache HttpClient apache apache

UTF-8 encoding problem with servlet and apache HttpClient


Have you tried

response.setCharacterEncoding("utf-8");

instead of setting the encoding via setContentType? It shouldn't make a difference according to the documentation, but who knows...

Also, make sure you didn't call response.getWriter() anywhere in your code before setting the character encoding, because the latter would not have any effect in that case.


StandardCharsets.UTF_8 can be used with EntityUtil to get the proper encoding.

Here is a sample snippet:

HttpEntity entity = response.getEntity();String webpage = EntityUtils.toString(entity, StandardCharsets.UTF_8);


Make sure stream bytes are in UTF-8 format:

out.write((yourstring.getBytes("UTF-8"));