1 @Override 2 public void doPost(HttpServletRequest reqeust, HttpServletResponse response) 3 throws ServletException, IOException { 4 5 //PrintWriter out = response.getWriter();在还没有给response指定编码格式时就获取了他的输出流,所以一直乱码 6 7 reqeust.setCharacterEncoding("utf-8"); 8 response.setContentType("text/html;charset=utf-8"); 9 response.setCharacterEncoding("utf-8"); 10 PrintWriter out = response.getWriter(); //在设置完编码以后在获取输出流就好了。 11 jsonService = new JsonService(); 12 String jsonString = JsonTools.createJsonString("persons", jsonService.getPersonList()); 13 out.println(jsonString); 14 out.flush(); 15 out.close(); 16 }