Illegal hex characters in escape (%) pattern
场景:运用URLDecoder.decode 报URLDecoder: Illegal hex characters in escape (%) pattern
使用URLDecoder.decode 报URLDecoder: Illegal hex characters in escape (%) pattern
使用URLDecoder.decode() 方法接收参数时如果参数中含有“%”这个字符,就会抛异常 java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern -,
不知道如何解决,求高手赐教解决方法,网上搜过,由于公司限制网址,所有没有查到解决的办法
代码:
如前台传参这两个
oid=37729&sendReson=是的%试试
private HashMap<String, Object> getRequestParamByPost()
{
HashMap<String, Object> paraMap = new HashMap<String, Object>();
try
{
String requestJson = URLDecoder.decode(
this.getRequestJsonObject() == null ? "" : this
.getRequestJsonObject(), "UTF-8");
this.log.info(requestJson);
if (requestJson != null && !requestJson.equals(""))
{
String[] requestJsonArr = requestJson.split("&");
String[] tempArr = null;
for (String str : requestJsonArr)
{
tempArr = str.split("=");
if (tempArr != null && tempArr.length == 2)
{
paraMap.put(tempArr[0], tempArr[1]);
}
}
}
}
catch (UnsupportedEncodingException e)
{
this.log.error("获取post参数出错:" + e);
}
return paraMap;
}
代码红色部分地方就报错了,除了使用其他字符替换%外,还有其他解决的办法吗
------解决方案--------------------
传参数的时候用encodeURIComponent("是的%试试")
%被URL认为是转义的标记,URL规范有自己的规定,%25会被转义成%!你现在的%后面跟了个中文字符,它要转义的时候发现'%试'是它不认识的,就给你报错了!
------解决方案--------------------

使用base64是个不错的选择!
------解决方案--------------------
Java6自带了jar包的,只要引用下:
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
使用URLDecoder.decode 报URLDecoder: Illegal hex characters in escape (%) pattern
使用URLDecoder.decode() 方法接收参数时如果参数中含有“%”这个字符,就会抛异常 java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern -,
不知道如何解决,求高手赐教解决方法,网上搜过,由于公司限制网址,所有没有查到解决的办法
代码:
如前台传参这两个
oid=37729&sendReson=是的%试试
private HashMap<String, Object> getRequestParamByPost()
{
HashMap<String, Object> paraMap = new HashMap<String, Object>();
try
{
String requestJson = URLDecoder.decode(
this.getRequestJsonObject() == null ? "" : this
.getRequestJsonObject(), "UTF-8");
this.log.info(requestJson);
if (requestJson != null && !requestJson.equals(""))
{
String[] requestJsonArr = requestJson.split("&");
String[] tempArr = null;
for (String str : requestJsonArr)
{
tempArr = str.split("=");
if (tempArr != null && tempArr.length == 2)
{
paraMap.put(tempArr[0], tempArr[1]);
}
}
}
}
catch (UnsupportedEncodingException e)
{
this.log.error("获取post参数出错:" + e);
}
return paraMap;
}
代码红色部分地方就报错了,除了使用其他字符替换%外,还有其他解决的办法吗
------解决方案--------------------
传参数的时候用encodeURIComponent("是的%试试")
%被URL认为是转义的标记,URL规范有自己的规定,%25会被转义成%!你现在的%后面跟了个中文字符,它要转义的时候发现'%试'是它不认识的,就给你报错了!
------解决方案--------------------
使用base64是个不错的选择!
------解决方案--------------------
Java6自带了jar包的,只要引用下:
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* Base64解密
* @param key
* @return
* @throws Exception
*/
public static byte[] decoderBase64(String key) throws Exception {
return (new BASE64Decoder()).decodeBuffer(key);
}
/**
* Base64加密
* @param key
* @return
* @throws Exception
*/
public static String encoderBase64(byte[] key) throws Exception {
return (new BASE64Encoder()).encodeBuffer(key);
}