servlet 使用 response 输出中文乱码(out.write()、out.println()) 作者:马育民 • 2022-01-20 13:15 • 阅读:10254 ``` // 一定要在获取流之前调用,否则无效 resp.setContentType("text/html; charset=UTF-8"); resp.setCharacterEncoding("UTF-8"); // 有时不写也可以 PrintWriter out=resp.getWriter(); out.write("中文乱码测试"); out.println("中文乱码测试"); // 在springboot、springmvc中,必须加此行代码,否则可能报错 // out.flush(); out.close(); ``` 原文出处:http://malaoshi.top/show_1IX2cufPuzVT.html