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!!!).
- I have set the
URIEncoding="utf-8"
at the Connector tag (server.xml). - I have used setCharacterEncoding().
- I cheched the stack trace (no filters that might set encoding).
- I have set the LANG environment variable
- I cheched the HTTP Headers and they are correct (Content-Type=text/plain;charset=utf-8)
- I checked the encoding at the browser and it is correct (UTF-8)
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