java.lang.IllegalArgumentException: URLDecoder异常解决
生活随笔
收集整理的這篇文章主要介紹了
java.lang.IllegalArgumentException: URLDecoder异常解决
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
異常:
Exception in thread "main" java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u9"
?? ?at java.net.URLDecoder.decode(URLDecoder.java:194)
?? ?at com.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");轉載地址:https://blog.csdn.net/afgasdg/article/details/40304817
總結
以上是生活随笔為你收集整理的java.lang.IllegalArgumentException: URLDecoder异常解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring面向AOP之动态代理
- 下一篇: 标准IO概述和操作