Get URL Query parameters GWT - java

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();

Related

How to get value of query param array in spring boot?

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.

Pass parameters to URL placeholders in java

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.

How can I get the URL paramter dynamically in Java?

A url is hit from browser now I want to get that url in my dataBean to extract its parameters for some checks.
How can I get that URL dynamically in that particular databean?
for instance :
someone hit
https://someAddress/AjaxForm?id=someid
I need to capture this url and get value of Id. How to do it?
you can do something likewise,
request.getRequestURL() // gives your current URL
where request is an instance of HttpServletRequest.
UPDATED :
If you are trying to find parameter which are comes along with URL, then
rather then do above mentioned my trick,
directly do likewise,
request.getParameter("id");
String url=request.getRequestURL()
String id=request.getParameter("id");
To get the parameter from url
request.getParameter("id");
And to insert it, in javascript add the parameter by attaching it to url
var url=baseurl+"?id="+id;
in the doGET method you write
String idValue=request.getParameter("id");
so the method will look like this
protected void doGET(HTTPServletRequest request,HTTPServletResponse response){
//some code here
String idValue=request.getParameter("id");//idValue will hold the value you passed in URL
//some more code here
}

Uri.parse(), how to get the encoding correct?

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.

How can I get URL parameters which have no value?

access using URL:
http://127.0.0.1/test.jsp?action=test&abc
or
http://127.0.0.1/test.jsp?abc
how can I get the String "abc" ?
thanks for help :)
<% java.util.Enumeration names = request.getParameterNames();
while(names.hasMoreElements()){
out.println(names.nextElement() + "<br>");
}
%>
I don't think there is a simple way to do this. Basically you need to iterate over the request's query parameter names and look for the parameter or parameters that don't have a value. I suspect that you will need to resort to embedding a Java scriptlet, or writing your own Tag (in Java).
A better idea is to stick to "name=value" syntax in your URL query.
request.getQueryString();
returns the whole query string after the URL.

Categories