1、 java.net.URLDecoder;
java.net.URLEncoder;
方法URLEncoder.encode()是编码
方法URLDecoder.decode()是解码,具体应用方法如图

2、常用的对中文乱码的解析,下图以将中文乱码转为gbk为例展示,如图
new String(test.getBytes("gbk"));
new String(test.getBytes("utf-8"),"gbk");
new String(test.getBytes("iso-8859-1"),"gbk");
new String(test.getBytes("gb2312"), "gbk");

3、在正常情况下tomcat会默认使用ISO8859_1来对这些参数的值进行编码,所以页面像后台传参乱码,用下面的方法就能解决
name = new String(name.getBytes("ISO-8859-1"),"utf-8");

4、js的encodeURI ()和 decodeURI()方法
对特殊含义的符号"; / ? : @ & = + $ , #"等不进行编码
编码: String str=encodeURI("中文")
解码:decodeURI(str)
用法如图

5、JSP页面乱码,在头部设置统一编码,<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />如图

6、java文件乱码设置,右键properties--resource--other选择编码,如图
