Using Java, Servlets, MySQL, Tomcat and Velocity, the following steps were taken:
- velocity.properties :
- input.encoding=UTF-8
- output.encoding=UTF-8
- server.xml
- URIEncoding = UTF-8
<html><head>Charset- meta http-equiv="Content-Type" content="text/html;CHARSET=UTF-8"
- eclipse properties, project properties, file & editor encoding
- set all that apply to UTF-8
- JDBC connection:
- db.url=jdbc:mysql://:/?useEncoding=true&characterEncoding=UTF-8
- java/servlet code:
- request.setCharacterEncoding( UTF-8 )
All of the above didn't work. Until the following code was done:
private String getParameter(String key) {
String param = request.getParameter(key);
if (Util.isNotEmpty(param)) {
try {
return new String(param.getBytes("8859_1"), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return param;
}
return null;
}
The above means that request.setCharacterEncoding didn't have an effect ( getCharacterEncoding() does return UTF-8 ); knowing that the request wrapper is wrapped in a ThreadLocal object.
How is this caused and how can I solve it?
charsetattribute in the HTTP responseContent-Typeheader. Note that the<meta>tag is ignored when the page is served over HTTP. Instead, the charset attribute of the HTTP response Content-Type header will be used, if any. The<meta>tag is only used when the user saves the webpage to its local disk and then views it later from the disk on byfile:///. Your problem needs likely to be solved in the Velocity side. - BalusC