简体   繁体   中英

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

I'm writing a lucene server. I want to receive the post query 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 get the wrong result:

" title:goole type:website" , because the URLDecoder convert the plus sign "+" into a space character " ". What can I do to get the decode argument without converting plus sign?

You can try this:

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

It will replace all plus signs and after that you use the decoder, which will convert back the plus sign

实际上所有空格都将被%20替换,因此一旦获得URL字符串,您就可以将所有%20替换为空格。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM