解决Servlet中文乱码的问题

在Servlet中,你的数据获取到了,但是中文是“?”,出现一个输出中文乱码的问题,把下面三行代码加上就可以了

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

request.setCharacterEncoding("utf-8");//1

response.setContentType("text/html;charset=utf-8");//2

response.setCharacterEncoding("utf-8"); //3

HandleImpl xm = new HandleImpl();

List list = xm.getStudentes();

JSONArray json=JSONArray.fromObject(list);

PrintWriter out = response.getWriter();

out.println(json);

out.flush();

out.close();

}---------------------本文来自 听雨季节 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/qq_30072293/article/details/76976130?utm_source=copy

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容