java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape


java编码解码

前两天修改了个功能,登陆的时候密码为‘%qwertyu’,在解码的时候出现了这个异常java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "qw"


本地测试


import java.net.URLDecoder;
import java.net.URLEncoder;
String domain = "中国.中国";
String password = "%qwertyu";
			
			
			try {					domain = URLEncoder.encode(domain, "gbk");
	password = URLEncoder.encode(password,"gbk");
	System.out.println("domain: " + domain);
	System.out.println("password:" + password);
	domain = URLDecoder.decode(domain, "gbk");
	password = URLDecoder.decode(password, "gbk");
	System.out.println("domain: " + domain);
	System.out.println("password:" + password);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			


输出结果:


domain: %D6%D0%B9%FA.%D6%D0%B9%FA
password:%25qwertyu
domain: 中国.中国
password:%qwertyu




但是写到线上,在action中编码,到jsp中解码,还是报上边的异常,后来请教了一下同事,同事说jsp中它自动解码了,所以再调用解码函数的时候就出现了异常信息,所以在线上的jsp中就不用解码了。


你可能感兴趣的:(exception)