为什么tomcat8里为什么get请求没有乱码
为了弄清这个问题,要分析jsp->服务器直接的编码过程,如下图
Get是URL解码方式。默认解码格式是Tomcat8编码格式。
为什么get方式在tomcat8以后得到了解决,因为tomcat8已经对get方式中文乱码进行了处理,url的默认编码方式是utf-8. 这在tomcat8中的server.xml中就可以看出来.
tomcat8:
URIEncoding
This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, UTF-8 will be used unless the org.apache.catalina.STRICT_SERVLET_COMPLIANCE system property is set to true in which case ISO-8859-1 will be used.
这个参数用来设置解码url参数,如果没指定,默认是UTF-8,除非设置了
Post是实体内容解码方式。默认解码格式是request编码格式。与Tomcat8编码格式无关,默认以ISO8859-1的编码解析数据,所以在getParameter()数据前必须加上request.setCharacterEncoding(“utf-8”)