• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with URLDecoding  RSS feed

 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have two quetions
I am using URLEncoding and URLDecoding classes to send info. in query string to the servlet and decoding respectively.

1) If I have % letter in between query strings, it gives me exception as java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern.
I searched regarding the same on the internet, found that % is treated as escape sequence character hence it throw the exception.
Now my question i what is the workaround for the same?

2) I am encoding the query string which has & in the string, when I retrive the query string on the servlet side using request.getParameter() and then NOT decoding ....
Strill I get the correct result. How is it so? I am confused....

Thanks in advance.
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "% letter in between query strings"? Please give an example of an URL both unencoded and URL-encoded.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
% should be represented as %25 in query strings.
 
Rahul Ba
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I write simple java class below example works fine...


but in below example does not works

send.do?param=URLEncoder.encode("GREAT BANK% PROFITLINE","UTF-8")

In servlet send.java




It throws exception on 111 line as below

java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern

but if we remove the line 111 and print the value of the rparam I get the correct result. I am confused with this secenario. if anybody has info. regarding this please share it.

Thanks once again.


 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URLDecode assumes that you have a properly encoded string. If it's not valid, you will get that failure..

Bottom line: don't decode invalid strings.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the servlet request does its own decoding, so you don't need to do it manually again.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!