get提交中文乱码问题解决

方法一: get方式提交的参数编码,只支持iso8859-1编码。因此,如果里面有中文。在后台就需要转换编码,如下 
String bname = request.getParameter("bname"); 
bname = new String(bname .getBytes("iso8859-1"),"utf-8");
 

前提是你页面编码就是utf-8,如果是gbk,那上面那句代码后面就改成gbk。 

方法二:修改tomcat的server.xml文件: 

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/> 

  • 添加URIEncoding="UTF-8" useBodyEncodingForURI="true"

猜你喜欢

转载自blog.csdn.net/zhao_tong/article/details/80186848