Servlet输出中文乱码的解决方法
Servlet输出中文乱码的解决方法如下例子:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//在PrintWriter前加上如下三行代码即可
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
ArrayList<DataInfo> list=DataSets.getDataInfo();
String json=DataSets.dataJson(list);
PrintWriter out = response.getWriter();
out.println(json);
out.close();
}