后台乱码解决

来源:互联网 发布:linux sleep函数没动作 编辑:程序博客网 时间:2024/06/05 01:02

工作中遇到一个乱码问题,在"url?"后面直接传参,查询sql语句的时候出现乱码“???”;


1、首先我在tomcat中的server.xml中配置参数

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

还是不好使;
于是在控制层的java文件中用了 new String("".getBytes("iso-8859-1"),"UTF-8");

还是乱码;


2、解决:
最后在后台加了  String gzqy = java.net.URLDecoder.decode(request.getParameter("gzqy"),"UTF-8").trim();
对应前台加了: url: "getRepairInfo.do?gzqy="+encodeURI(encodeURI(gzqy))
问题解决了;
0 0