As shown below:
A problem of outputting Chinese garbled code in Servlet has been solved. @Override public void doPost(HttpServletRequest reqeust, HttpServletResponse response) throws ServletException, IOException { //PrintWriter out = response.getWriter(); It obtained its output stream before the encoding format was specified for the response, so it kept garbled reqeust.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); //After setting the encoding, just get the output stream. jsonService = new JsonService(); String jsonString = JsonTools.createJsonString("persons", jsonService.getPersonList()); out.println(jsonString); out.flush(); out.close(); }The above article perfectly solves the problem of outputting Chinese garbled code in Servlet. This is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.