1.get方式请求如果出现乱码
解决:
a.统一每一个变量的 编码 (不推荐)
new String( 旧编码,新编码);
name = new String(name.getBytes("iso-8859-1"),"utf-8");
b. 修改server.xml ,一次性的 更改tomcat默认get提交方式的编码 (utf-8)
建议 使用tomcat时, 首先在server.xml中 统一get方式的编码.. URIEncoding="UTF-8"
<Connector URIEncoding="UTF-8" connectionTimeout="20000" maxHttpHeaderSize="8192" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
tomcat7 (默认iso-8859-1)
tomcat8(默认utf-8)
2.post方式请求如果出现乱码
解决:
request.setCharacterEncoding("utf-8") ;