Decoding URI query string in Java

Use

URLDecoder.decode(proxyRequestParam.replace("+", "%2B"), "UTF-8")
          .replace("%2B", "+")

to simulate decodeURIComponent. Java’s URLDecoder decodes the plus sign to a space, which is not what you want, therefore you need the replace statements.

Warning: the .replace("%2B", "+") at the end will corrupt your data if the original (pre-x-www-form-urlencoded) contained that string, as @xehpuk pointed out.

Leave a Comment