我们经常在jsp页面通过url传入中文参数,在action中去接收会发现中文乱码了,这时候我的解决办法是进行判断 如:
String empName = "您从url传过来的中文参数";
if(empName.equals(new String(empName.getBytes("GB2312"), "GB2312"))){
empName = new String(empName.getBytes("GB2312"),"utf-8");
}else if(empName.equals(new String(empName.getBytes("iso-8859-1"), "iso-8859-1"))){
empName = new String(empName.getBytes("iso-8859-1"),"utf-8");
}else if(empName.equals(new String(empName.getBytes("UTF-8"), "UTF-8"))){
empName = new String(empName.getBytes("UTF-8"),"utf-8");
}else if(empName.equals(new String(empName.getBytes("GBK"), "GBK"))){
empName = new String(empName.getBytes("GBK"),"utf-8");
}
应该我们系统编码标准时utf-8形式,所以我直接通过判断,然后使其自动转换,这样就解决了中文乱码问题。。。。。