Tomcat does not correctly encode string literals containing Unicode characters. The problem occurs on a Linux server, but not on my development machine (Windows). It affects only String literals (not strings read from the database or from the file !!!).
- I set
URIEncoding="utf-8" in the Connector tag (server.xml). - I used setCharacterEncoding ().
- I checked the stack trace (no filters that could set the encoding).
- I set the LANG environment variable
- I intercepted the HTTP headers and they are correct (Content-Type = text / plain; charset = utf-8)
- I checked the encoding in the browser and correctly (UTF-8)
None of the above work. 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");
The above shows this in a browser. ÎÎ "Î" Î · νικά Latin
idrosid
source share