1. Set the following in web.xml
<request-character-encoding>UTF-8</request-character-encoding> <response-character-encoding>UTF-8</response-character-encoding>
2. Create a servlet like the following
@WebServlet("/test") public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { res.setContentType("text/plain"); PrintWriter pw = res.getWriter(); pw.println("REQ_CHAR_ENC = " + req.getCharacterEncoding()); pw.println("RES_CHAR_ENC = " + res.getCharacterEncoding()); } }
3. Running the servlet produces the following output.
REQ_CHAR_ENC = null RES_CHAR_ENC = ISO-8859-1
The default character encoding setting in web.xml added in Servlet 4.0 is not working.