前台:
使用encodeURI()转码
var param = "中文";
get方式提交
var url = "aa.html?param="+ encodeURI(param);
后台:
String problem = new String(URLDecoder.decode(request
.getParameter("param"), "utf-8"));
这样转码过后,输出来的值就不会出现乱码了。
字符串解码:
System.out.print(new String(request.getParameter("fileName").getBytes("GBK"),"UTF-8"));
System.out.print(new String(request.getParameter("fileName").getBytes("ISO-8859-1"),"GBK"));
System.out.print(new String(request.getParameter("fileName").getBytes("UTF-8"),"GBK"));
System.out.print(new String(request.getParameter("fileName").getBytes("ISO-8859-1"),"UTF-8"));