首页 > Web开发 > 详细

解决HttpServletResponse输出的中文乱码问题

时间:2017-04-12 15:39:23      阅读:216      评论:0      收藏:0      [点我收藏+]

 

 

主要有这三行代码就可以了。

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输出的中文乱码问题

原文:http://www.cnblogs.com/huichao1314/p/6699461.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!