How to get the parameter value, since it is associated with the URL with JSP

I have a value like var = P+q+EvhE951eg/I5nz1vi/w2YpJdH+v/vSPaQNg/I=

I pass this parameter in url as

http://localhost/proj/home.jsp?var=P+q+EvhE951eg/I5nz1vi/w2YpJdH+v/vSPaQNg/I=

Now in home.jsp I want to use this var value as is. But when I do

String var=request.getParameter("var"); var get value

"P q EvhE951eg/I5nz1vi/w2YpJdH v/vSPaQNg/I=" note the replacement of + with space .

So can someone help me solve this problem.

+5
source share
2 answers

Try the encoding options as follows:

 class Ideone { public static void main (String[] args) throws java.lang.Exception { String param = "P+q+EvhE951eg/I5nz1vi/w2YpJdH+v/vSPaQNg/I="; System.out.printf("Orginal Param: %s\n", param); param = java.net.URLEncoder.encode(param, "utf-8"); System.out.printf("Encoded Param: %s\n", param); } } 

Conclusion:

 Orginal Param: P+q+EvhE951eg/I5nz1vi/w2YpJdH+v/vSPaQNg/I= Encoded Param: P%2Bq%2BEvhE951eg%2FI5nz1vi%2Fw2YpJdH%2Bv%2FvSPaQNg%2FI%3D 
0
source

"+" means "space" in Url. you can copy this% 2B.

Example

 queryString = queryString.replace('+', '%2B'); 

Link Link

if there is only one parameter in the query string.

you can also get this via request.getQueryString () - there is no need to replace the query string here.

 String urlContent = request.getQueryString(); 

Output: var = P + q + EvhE951eg / I5nz1vi / w2YpJdH + v / vSPaQNg / I =

0
source

Source: https://habr.com/ru/post/1204395/


All Articles