HttpServletResponse输出的中文乱码
2015-09-18 21:50
531 查看
HttpServletResponse输出有两种格式,一种是字符流,一种是字节流。
1.字符流
2.字节流
参考:
http://blog.csdn.net/kontrol/article/details/7767983
1.字符流
// 这句话的意思,是让浏览器用utf8来解析返回的数据,即设置客户端解析的编码 response.setContentType("text/html; chartset=UTF-8"); //这句话的意思,是告诉servlet用UTF-8转码,而不是用默认的ISO8859 ,即服务端对中文的编码 response.setCharacterEncoding("UTF-8"); PrintWriter printWriter = response.getWriter(); printWriter.print("中文");
2.字节流
// 这句话的意思,是让浏览器用utf8来解析返回的数据,即设置客户端解析的编码 response.setHeader("Content-type", "text/html;charset=UTF-8"); // response.setContentType("text/html; chartset=UTF-8"); //尝试使用这个设置“Content-type”未成功 String data = "中文"; OutputStream ps = response.getOutputStream(); // 这句话的意思,使得放入流的数据是utf8格式 ps.write(data.getBytes("utf-8"));
参考:
http://blog.csdn.net/kontrol/article/details/7767983
相关文章推荐
- python网络爬虫
- http content-type
- VMware的三种网络连接方式
- http 的get,put,post,delete
- Http的Cache机制
- TCP/IP协议原理与应用笔记05:TCP/IP协议下的网关
- 网络图可视化工具
- 网络配置
- linux下C语言socket网络编程简例
- TCP/IP协议原理与应用笔记04:子网掩码
- 我的WebUtil工具类--获取IP与发送http请求
- 长春网络赛 1108
- 长春网络赛 1102
- 长春网络赛 1101
- Http请求中Content-Type讲解以及在Spring MVC中的应用
- 网络编程
- App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Te
- 网络的基本概念TCP, UDP, 单播(Unicast), 多播(多播)(Multicast)
- Android网络访问Post请求的两种写法
- iOS9网络请求失败问题