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

在使用get方式URL中传递中文,到后台会出现乱码的情况。中文字符变为"?"
如:我的jsp页面代码为:
查看龙虎榜
传到后台后发现中文字符变成了"?"

我的解决方案有两种
方案一:修改tomcat的server.xml文件,添加一项参数URIEncoding="UTF-8"

 
然后重新启动服务器就好了

方案二:在后台做转码
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 block
	e.printStackTrace();
    }



你可能感兴趣的:(java)