Web工程乱码

方法一: 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"


原文链接:https://blog.csdn.net/zhao_tong/article/details/80186848

posted @ 2022-01-11 15:10  Mrzxs  阅读(47)  评论(0编辑  收藏  举报