I have this URL
http://127.0.0.1:3009/mac/view/:userId?ot-replace[0]=kin43
I need the value of ot-replace[0]
In the controller I am using
#RequestParam(name="ot-replace", required=false)String[] regexReplace
Also tried using
#RequestParam(name="ot-replace", required=false)List<String> regexReplace
I always get null.
Not sure what is the issue here
Your URL should like this.
http://127.0.0.1:3009/mac/view/:userId?ot-replace=kin43,value2,vlue3
then
you can get a String[].
ot-replace[0]=kin43
ot-replace[1]=value2
ot-replace[2]=value3
Try to use a POST methood when excute your url and set your array in the request body.
Related
I have an HTTP GET request controller endpoint where I take in a fileName as a query param and pass that on to another service. For this request the param the filename could include any sort of special characters and I would like to keep these values encoded when passing them on. 2 Characters that have been causing issues are spaces (%20) and +(%2B).
How can I keep these characters encoded in the request params.
So far I have tried using the #RequestParam annotation as well as retrieving the params via HttpServletRequest.getParameterValues(String) but both return the decoded values as spaces.
Any help is appreciated thanks!
Yes, these are automatically decoded by the servlet API. You should be able to re-encode them -
encodedValue = URLEncoder.encode(value, StandardCharsets.UTF_8);
I found out that I could get the actual value passed in by using the HttpServletRequest.getQueryString() method. Parsing this query string I was able to get the un-decoded version of the fileName being passed in. I hope this helps someone in the future.
I am getting the URL dynamically which has few placeholders. But i need to pass the parameters to the placeholders.
Below is the URL which i am getting dynamically
http://example.com/name/{name}/age/{age}
i need to pass parameters for name and age for the above url. How can we achieve that using java.
I guess you are looking Rest Client to call this URL and get response.
http://example.com/name/{name}/age/{age}
String resourceURL = "http://example.com/name";
ResponseEntity<String> response = restTemplate.getForEntity(resourceURL + "/swarit/age/20", String.class);
I would also suggest to do little research before posting question.
I have this URI:
http://IP5:port/notification/myServlet.do?method=myMethod¶m1=[08]&method2=anotherParam¶m0=[07,04,06]
I want to obtain the URI's last part in the same order:
method=myMethod¶m1=[08]&method2=anotherParam¶m0=[07,04,06]
But' I can't discover how:
I can see in the request the field input, in order to do a substring after of ? character...
the methods: request.getRequestURI() and request.getRequestURL() is not working for me.
It looks like request is an HttpServletRequest. If so, you should be able to get what you are looking for using request.getQueryString().
I need to get "query parameters" from this URL with GWT:
127.0.0.1:8888/App.html?gwt.codesvr=127.0.0.1:9997#Login&oauth_token=theOauthToken&oauth_verifier=123456
I need to get the oauth_verifier
However, Window.Location.getParameter("oauth_verifier"); is returning null.
How to get this?
You can try this using getHash():-
string s= Window.Location.getHash();
I am doing an application where I have to read a URL from a webpage as a String[Its not the address of the page]. The URL that I will be reading contains query string, and I specifically need two queries from that URL. So I am using the Uri class available in Android. Now, the problem lies in the encoding/format of the URL and the query. One of the queries that I need is always an URL. Sometimes the query URL is %-encoded and sometimes not.
The URLs can be like the following :
Case 1 :
http://www.example.com/example/example.aspx?file=http%3A%2F%2FXX.XXX.XX.XXX%2FExample.file%3Ftoken%3D9dacfc85
Case 2 :
http://www.example.com/example/example.aspx?file=http://XX.XXX.XX.XXX/Example.file?token=9dacfc85
How do I get the correct Url contained in the file= query?
I am using the following [to accomplish the said work universally] :
Uri.decode(urlString.getQueryParameter("file"));
Is this the correct way to do it?
UPDATE
I have decided to first encode the whole URL regardless of its value and then get the query parameter. Theoretically, it should work.
If you are uncertain about the type of URL you would get then I would suggest you to decode every URL you get from the parameter. And when you need to use it then you can encode it.
As per my knowledge, you are doing it right.