Get request parameter from url with & symbol

I am trying to get a query parameter that has '&' sybol at the beginning, like: - http://localhost:8080/simple.jsp?my=&234587

On another page, I get it as String value=request.getParameter("my"); value.substring(0,4); String value=request.getParameter("my"); value.substring(0,4);

I want to receive & 234, please suggest that I do not receive any value.

Thanks Ars

+4
source share
4 answers

In this example, you do not have one, but two parameters:

  • my
  • 234

234 is not a value here. The & parameter separates the request parameters. If you need this ampersand to be part of the value of my , it must be escaped in the URL as %26 .

+4
source

thanks for the answer, I found the answer, I used request.getQueryString(); to get the whole line ie & 234587, and then parsed it accordingly.

:)

Thanks again.

+2
source

You will most likely have to encode '&' in the URL:

http://localhost:8080/simple.jsp?my=%26234587

0
source

If you only process the Get request. You can write something like this.

 String requestURI=request.getRequestURI(); String pContent=requestURI.split("?")[1]; String[] pArray= pContent.split("&"); String value=""; for (int i=0 ;i<pArray.length;i++) { if(pArray[i].equals("my"+"=")){ value="&" + pArray[i+1]; break; } } 
0
source

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


All Articles