response.setCharacterEncoding和response.setContentType区别

这两句代码都是设置字符集为utf-8
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");

response.setContentType作用是让浏览器用utf-8来解析返回的数据
response.setCharacterEncoding作用是告诉servlet用utf-8转码,而不是用默认的iso8859-1

参考资料:

https://blog.csdn.net/tlms_/article/details/78749980

猜你喜欢

转载自blog.csdn.net/csj50/article/details/86713867