2

My Tomcat web server is using Struts framework (v1).

When reading request parameters, i need to recode the parameter from ISO-8859-1 to UTF-8 in order to get proper value. e.g.

String fName = request.getParameter("fName");
String displayName = new String(fName.getBytes("ISO-859-1"), "UTF-8");
persistName(displayName);

The question is why the default encoding is ISO-8859-1? Where is it defined and how to change it?

Env details:

  • Server version: Apache Tomcat/7.0.62
  • OS Name: Linux
  • JVM Version: 1.8.0_92-b14
itamar
  • 1,800
  • 4
  • 17
  • 30

2 Answers2

3

I think, if I recall correctly, you can set the URIEncoding property on the connector to default to UTF-8.

According to this link, the default under Tomcat 8 (when strict servlet compliance is off) is UTF-8. Under Tomcat 7, at my company we set this explicitly.

In server.xml for the connector element(s):

<Connector port="80" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="443" URIEncoding="UTF-8"/>

According to the configuration documentation for the Tomcat 7 HTTP connector, this is by default ISO-8859-1.

The configuration documentation for the Tomcat 8 HTTP connector does explicitly state that if org.apache.catalina. STRICT_SERVLET_COMPLIANCE is false, UTF-8 will be used.

I do have some inklings that this dates back to Servlet 2.4 specification which states that if no character encoding is specified, ISO-8859-1 is used.

Dave G
  • 9,639
  • 36
  • 41
0

Check that encoding of your files are utf-8 and the charset meta tag in html are also set to utf-8.

bilgec
  • 171
  • 7