java使用PrintWriter向前端打印示例
解决方法:
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException var4) {
throw new RuntimeException("输出json错误");
}
if (msgObj instanceof String) {
out.write((String)msgObj);
} else {
out.write(JSON.toJSONString(msgObj));
}
out.flush();
out.close();