Java: use URLDecoder but reserve the plus sign (+)

I am writing a lucene server. I want to receive a post request like:
http://www.site.com/search?+title:google + type: website

but the post argument "+ title: google + type: website" is encoded like this: "+ title: google% 20 + type: website" so I use URLDecoder.decode (argument, "UTF-8") to get the original input, but i am getting wrong result:

"title: goole type: website" because URLDecoder converts the plus sign "+" to the space character "". What can I do to get the decoding argument without converting the plus sign?

+3


source to share


2 answers


Actually all spaces will be replaced with% 20, so you can replace all% 20 with a space after getting the URL string.



0


source


You can try this:

"+ title: google% 20 + type: website" .replaceAll ("\\ +", "% 2B")



It will replace all plus signs and after that you will use a decoder that converts the plus sign

+4


source







All Articles