一.post乱码
原因:
因为post是以二进制流的形式发送到的服务器。服务器收到数据后,默认以iso-8859-1进行编码。
解决:
POST请求乱码解决,只需要在获取请求参数之前调用request.setCharacterEncoding(“UTF-8”); 方法设置字符集 即可。如下:
二.get乱码
原因:
1.页面提交数据时以utf-8对内容进行编码
2.把编码后的内容传到tomcat服务器3.服务器会用ISO-8859-1解码,导致乱码
解决:
解决乱码的核心思路,就是把得到的乱码按照原来乱码的步骤逆序操作。
1、先以iso-8895-1进行编码2、然后再以utf-8进行解码三.返回浏览器中文乱码
原因:
主要是因为服务器输出的字符串的编码和客户端显示字符串的编码不一致。导致乱码问题
解决:
我们只需要设置服务器和客户端的编码相同就可以解决这个问题。