Tomcat does not encode correctly String literals that contain unicode characters. The problem occurs at a Linux server but not on my development machine (Windows). It affects ONLY String literals (not Strings read from DB or from file!!!).
URIEncoding="utf-8"
at the Connector tag (server.xml). Nothing of the above works. Any ideas on what I might be missing?
public class Test extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/plain;");
Writer w = resp.getWriter();
w.write("Μαλακία Latin"); //Some unicode characters
w.close();
}
The above shows this at the browser. Îλληνικά Latin
You can force the encoding of files when javac reads them by passing in -encoding 'utf-8' or -encoding 'iso-8859-1' when compiling. Just make sure that it matches whatever encoding your .java files are actually encoded as.
http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
-encoding encoding Set the source file encoding name, such as EUC-JP and UTF-8. If -encoding is not specified, the platform default converter is used.
尝试在Linux JVM命令行上设置file.encoding系统属性,例如-Dfile.encoding=utf-8
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.