在Servlet中出现一个输出中文乱码的问题,已经解。
	@Override
	public void doPost(HttpServletRequest reqeust, HttpServletResponse response)
			throws ServletException, IOException {
		
                //PrintWriter out = response.getWriter();在还没有给response指定编码格式时就获取了他的输出流,所以一直乱码

		reqeust.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter(); //在设置完编码以后在获取输出流就好了。
		jsonService = new JsonService();
		String jsonString = JsonTools.createJsonString("persons", jsonService.getPersonList());
		out.println(jsonString);
		out.flush();
		out.close();
        }

以后得在细节上多小心才行。

  

 

相关文章:

  • 2022-12-23
  • 2021-07-21
  • 2021-05-12
  • 2021-04-18
  • 2021-11-06
  • 2022-02-18
  • 2022-02-10
猜你喜欢
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-11-13
  • 2021-08-25
  • 2022-02-10
相关资源
相似解决方案