java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " 0"
2017-02-14 15:48
1021 查看
value = URLDecoder.decode(request.getParameter(paraName), "UTF-8");
前端用了 encodeURI 来编码参数,后端用 URLDecoder 解码,报错:
java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " 0"
http://stackoverflow.com/questions/6067673/urldecoder-illegal-hex-characters-in-escape-pattern-for-input-string
Characters that get encoded have % and + signs in them, so although this helps with % and + characters in a string, it also doesn't decode things like %20 (space) because you are taking out the percent before decoding.
A solution is to replace %2B (+) and %25 (%) instead. Something like:
"+" is a special character which denotes a quantifier meaning one of more occurrences. So one should use "\+"
前端用了 encodeURI 来编码参数,后端用 URLDecoder 解码,报错:
java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " 0"
http://stackoverflow.com/questions/6067673/urldecoder-illegal-hex-characters-in-escape-pattern-for-input-string
Characters that get encoded have % and + signs in them, so although this helps with % and + characters in a string, it also doesn't decode things like %20 (space) because you are taking out the percent before decoding.
A solution is to replace %2B (+) and %25 (%) instead. Something like:
public static String replacer(StringBuffer outBuffer) { String data = outBuffer.toString(); try { data = data.replaceAll("%(?![0-9a-fA-F]{2})", "%25"); data = data.replaceAll("\\+", "%2B"); data = URLDecoder.decode(data, "utf-8"); } catch (Exception e) { e.printStackTrace(); } return data; }
"+" is a special character which denotes a quantifier meaning one of more occurrences. So one should use "\+"
相关文章推荐
- URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "6#" 解决方法
- Escape 解决中文乱码(URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u6")
- URLDecoder: Illegal hex characters in escape (%) pattern - For input string:
- URLDecoder: Illegal hex characters in escape (%) pattern - For input string:
- 【URLDecoder】java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in es
- Could not open the editor: URLDecoder: Illegal hex characters in escape (%) pattern - For input stri
- 使用Retrofit时出现 java.lang.IllegalArgumentException: URL query string "t={type}&p={page}&size={count}" must not have replace block. For dynamic query parameters use @Query.异常原因
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: input == null!
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.NumberFormatException: For input string: "2016/09/12 09:41:48"
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://node1:9000/input/pia