Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java URLDecoder decode Percentage Symbol as error

Tags:

java

urldecode

I need to allow user to input various special characters, so i use the java URLDeacoder.decode() method, i tested using println. There is no problem with other special character except this Percentage symbol, it has error during execute. Why is that? I understand that % is being used for URL encoding, is this the reason?

java.lang.IllegalArgumentException: URLDecoder: Incomplete trailing escape (%) pattern

System.out.println(URLDecoder.decode("%", "UTF-8"));
like image 744
hades Avatar asked Jun 30 '26 15:06

hades


1 Answers

Despite their names, URLEncoder/Decoder are for encoding POST arguments, not URLs. See @fge's remarks below.

The way to encode a URL is with the URL and URI classes.

I'm curious as to how you acquired an undecoded URL in the first place.

like image 77
user207421 Avatar answered Jul 02 '26 04:07

user207421



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!