jsp页面中url传参到后台出现乱码解决方案

来源:互联网 发布:jquery传json数据 编辑:程序博客网 时间:2024/06/09 15:51
在使用get方式URL中传递中文,到后台会出现乱码的情况。中文字符变为"?"
如:我的jsp页面代码为:
<a href="${_currConText}/lhRanking/ranking.do?investors_code=${inves.investors_code}&investors_name=${inves.investors_name}">查看龙虎榜</a>
传到后台后发现中文字符变成了"?"
我的解决方案有两种
方案一:修改tomcat的server.xml文件,添加一项参数URIEncoding="UTF-8"
 <Connector URIEncoding="UTF-8"connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
然后重新启动服务器就好了
方案二:在后台做转码
try {String str = new String(investors.getInvestors_name().getBytes("iso8859-1"),"utf-8");System.out.println("investors_name="+str+"======");    } catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();    }


原创粉丝点击