Java response返回给前端中文乱码
public void errPrint(HttpServletResponse response, String msg, Object data) { try { response.reset(); response.setCharacterEncoding("UTF-8"); response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); response.setContentType("application/json;charset=UTF-8"); response.setStatus(500); Result result = new Result(); result.setCode(500); result.setMsg(msg); result.setData(data); String s = new Gson().toJson(result); System.out.println(s); String characterEncoding = response.getCharacterEncoding(); OutputStream ps = response.getOutputStream(); //这句话的意思,使得放入流的数据是utf8格式 ps.write(s.getBytes("UTF-8")); } catch (Exception e) { } }