标签:err etc lap 代码 highlight rac ons cte print
主要有这三行代码就可以了。
request.setCharacterEncoding("utf-8");
response.setHeader("Content-type", "text/html;charset=UTF-8");
response.setCharacterEncoding("utf-8");
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setHeader("Content-type", "text/html;charset=UTF-8"); response.setCharacterEncoding("utf-8"); SpdDao dao=new SpdDaoImpl(); List<Spd> list=dao.getAllSpds(); // json Gson gson=new Gson(); if(list!=null){ String json = gson.toJson(new returnJson(true,"OK",list)); PrintWriter out = response.getWriter(); out.print(json); }else{ String json = gson.toJson(new returnJson(false,"ERROR")); PrintWriter out = response.getWriter(); out.print(json); }
解决HttpServletResponse输出的中文乱码问题
标签:err etc lap 代码 highlight rac ons cte print
原文地址:http://www.cnblogs.com/huichao1314/p/6699461.html