response输出乱码问题

来源:互联网 发布:学大数据能找到工作嘛 编辑:程序博客网 时间:2024/05/17 20:24
//这句话的意思,是让浏览器用utf8来解析返回的数据 response.setHeader("Content-type", "text/html;charset=UTF-8"); //这句话的意思,是告诉servlet用UTF-8转码,而不是用默认的ISO8859 response.setCharacterEncoding("UTF-8"); String data = "中国"; PrintWriter pw = response.getWriter(); pw.write(data);

经验:1,如果中文返回出现??字符,这表明没有加response.setCharacterEncoding("UTF-8");这句话。

            2,如果返回的中文是“烇湫”这种乱码,说明浏览器的解析问题,应该检查下是否忘加response.setHeader("Content-type", "text/html;charset=UTF-8");这句话。


如果上面都解决不了,请看更详细的说明

http://blog.csdn.net/kontrol/article/details/7767983


0 0
原创粉丝点击