JS加码encodeURI(str)
JS解码decodeURI(str)
JAVA解码URLDecoder.decode(str, "UTF-8");
摘要:Exception in thread main java.lang.IllegalArgumentException:URLDecoder: Illegal hex characters in escape (%) pattern - For input string: u9at java.net.URLDecoder.decode(URLDecoder.java:194) atcom.hbzx.controller.PayResultController.main(] Exceptionin thread "main" java.lang.IllegalArgumentException: URLDecoder:Illegal hex characters in escape (%) pattern - For input string: "u9" atjava.net.URLDecoder.decode(URLDecoder.java:194) atcom.hbzx.controller.PayResultController.main(PayResultController.java:253)
Java调用 URLDecoder.decode(str,"UTF-8"); 抛出以上的异常,其主要原因是% 在URL中是特殊字符,需要特殊转义一下,
解决办法:使用%25替换字符串中的%号
url =url.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
String urlStr = URLDecoder.decode(url,"UTF-8");
本文介绍了在Java中使用URLDecoder进行URL解码时遇到的非法十六进制字符错误,并提供了解决方案,即如何正确地处理百分号(%)以避免出现此类异常。
936

被折叠的 条评论
为什么被折叠?



