1. 代码: try (PrintWriter out = response.getWriter()) { response.setContentType("application/json; charset=utf-8"); JSONObject res = new JSONObject(); res.put("status", 401); res.put("message", "失败"); out.append(res.toString()); } catch (Exception e) { e.printStackTrace(); } 2. 页面显示的response:application/json; charset=ISO-8859-1
3. 修改后就生肖了:
response.setContentType("application/json; charset=utf-8"); try (PrintWriter out = response.getWriter()) { JSONObject res = new JSONObject(); res.put("status", 401); res.put("message", "失败"); out.append(res.toString()); } catch (Exception e) { e.printStackTrace(); }