您的位置:首页 > Web前端 > JavaScript

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

2017-08-03 17:44 351 查看
在使用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();}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: