response对象输出中文,产生乱码

来源:互联网 发布:javascript 移除元素 编辑:程序博客网 时间:2024/05/29 16:43

response对象输出中文,产生乱码:
* 字节乱码解决方案:1.设置浏览器打开文件时采用的编码
* response.setHeader("Content-Type", "text/html;charset=UTF-8"); 
* 2.获取字符串的Byte数组采用的编码
* "哈喽".getBytes("UTF-8")
* 实例://设置浏览器打开文件时编码
response.setHeader("Content-Type", "text/html;charset=UTF-8");
//获取字节输出流
OutputStream os = response.getOutputStream();
//输出中文
os.write("哈喽".getBytes("UTF-8"));
字符乱码解决方法:
1.设置浏览器打开文件时采用的编码
* response.setHeader("Content-Type", "text/html;charset=UTF-8"); 
* 2.设置response缓冲区的编码
* response.setCharacterEncoding("UTF-8");
* 简写上面两句:
* response.setContentType("text/html;charset=UTF-8");


0 0