Java. lang. IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern, escapecharacters
Value = URLDecoder. decode (request. getParameter (paraName), "UTF-8 ");
The frontend uses encodeURI to encode parameters, and the backend uses URLDecoder to decode parameters. An error is returned:
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 encodedHave % and + signsIn them, so although this helps with % and + characters in a string, it alsoDoesn'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 shocould use "\ +"