Monday, March 30, 2015

Set Tomcat encoding to UTF-8

By default, Tomcat uses ISO-8859-1 encoding, but there is a way to completely set tomcat using UTF-8.

-Dfile.encoding=UTF-8
Set JVM default encoding to UTF-8. Charset.defaultCharset() will reflect changes to the file.encoding property.

set JAVA_OPTS=-Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8
or Use a character encoding filter with the default encoding set to UTF-8, for HTTP POST

Set URIEncoding="UTF-8" on your <Connector> in server.xml.
<Connector port="8080" URIEncoding="UTF-8"/> for HTTP GET

For returned response, set
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");


http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q8
http://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps

No comments:

Post a Comment