Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java servlet: request parameter contains plus

Tags:

java

servlets

The request parameter is like decrypt?param=5FHjiSJ6NOTmi7/+2tnnkQ==.

In the servlet, when I try to print the parameter by String param = request.getParameter("param"); I get 5FHjiSJ6NOTmi7/ 2tnnkQ==. It turns the character + into a space. How can I keep the orginal paramter or how can I properly handle the character +.

Besides, what else characters should I handle?

like image 227
Cacheing Avatar asked Jan 12 '23 04:01

Cacheing


1 Answers

You have two choices

URL encode the parameter

If you have control over the generation of the URL you should choose this. If not...

Manually retrieve the parameter

If you can't change how the URL is generated (above) then you can manually retrieve the raw URL. Certain methods decode parameters for you. getParameter is one of them. On the other hand, getQueryString does not decode the String. If you have only a few parameters it shouldn't be difficult to parse the value yourself.

request.getQueryString();
//?param=5FHjiSJ6NOTmi7/+2tnnkQ==
like image 110
Amir T Avatar answered Jan 18 '23 22:01

Amir T