使用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;
}代码红色部分地方就报错了,除了使用其他字符替换%外,还有其他解决的办法吗
不知道如何解决,求高手赐教解决方法,网上搜过,由于公司限制网址,所有没有查到解决的办法代码:如前台传参这两个
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;
}代码红色部分地方就报错了,除了使用其他字符替换%外,还有其他解决的办法吗
解决方案 »
- Java多语言国际化实现方式探讨~~
- 关于什么时候用接口,什么时候用抽象类的讲解。
- 有没有比较好的开源的java知识库项目
- 谁有登录后,在抓取网页数据的例子啊
- spring+hibernate+struts 为什么换到 Myeclipse6.1 中就中出现错误
- JAVA编程:浏览器的cookie问题
- 这个小程序大概怎么写呀(大家别怪问题幼稚),初学者,不入门
- weblogic初始安装的时候是不装成windows系统服务,现在怎么改成windows系统服务?
- JAVA如何读入XML?
- java.sql.SQLException: 求助,弄了大半天
- 第一次尝试做系统遇到困难,求帮忙解决
- TOMCAT报错,求救!!!!
%被URL认为是转义的标记,URL规范有自己的规定,%25会被转义成%!你现在的%后面跟了个中文字符,它要转义的时候发现'%试'是它不认识的,就给你报错了!
使用base64是个不错的选择!
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);
}