前端乱码解决方案
前端接收乱码
1.response.addHeader("Content-Type", "text/xml" + "; charset=" + CommunicateService.charset);
2. 字节流
3. /////////////
4. //这句话的意思,是让浏览器用utf8来解析返回的数据
5. response.setHeader("Content-type", "text/html;charset=UTF-8");
6. String data = "中国";
7. OutputStream ps = response.getOutputStream();
8. //这句话的意思,使得放入流的数据是utf8格式
9. ps.write(data.getBytes("UTF-8"));
10. 字符流
11. ////////////
12. //这句话的意思,是让浏览器用utf8来解析返回的数据
13. response.setHeader("Content-type", "text/html;charset=UTF-8");
14. //这句话的意思,是告诉servlet用UTF-8转码,而不是用默认的ISO8859
15. response.setCharacterEncoding("UTF-8");
16. String data = "中国";
17. PrintWriter pw = response.getWriter();
18. pw.write(data);
>> 转载请注明来源:前端乱码解决方案
赏
免费分享,随意打赏
发表评论