Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT: Capturing URL parameters in GET request

Tags:

java

gwt

I need to build a GWT application that will be called by an external application with specific URL parameters.

For example:

http://www.somehost.com/com.app.client.Order.html?orderId=99999.

How do I capture the orderId parameter inside the GWT application?

like image 495
Otavio Avatar asked Feb 26 '09 13:02

Otavio


People also ask

How do I get parameters in GET request?

GET parameters (also called URL parameters or query strings) are used when a client, such as a browser, requests a particular resource from a web server using the HTTP protocol. These parameters are usually name-value pairs, separated by an equals sign = . They can be used for a variety of things, as explained below.

How can I get value from GET request URL?

Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&". Read more about passing parameter through URL.

Can a get request have a parameter?

GET requests don't have a request body, so all parameters must appear in the URL or in a header. While the HTTP standard doesn't define a limit for how long URLs or headers can be, mostHTTP clients and servers have a practical limit somewhere between 2 kB and 8 kB.

Can I pass URL as query parameter?

Yes, that's what you should be doing. encodeURIComponent is the correct way to encode a text value for putting in part of a query string. but when it is decoded at the server, the parameters of url are interpreted as seperate parameters and not as part of the single url parameter.


1 Answers

Try,

String value = com.google.gwt.user.client.Window.Location.getParameter("orderId"); // parse the value to int 

P.S. GWT can invoke native javascript which means if javascript can do the stuff, GWT can do it too; e.g. in GWT, you can write

public static native void alert(String msg) /*-{  $wnd.alert("Hey I am javascript"); }-*/; 

In this case, you can even use existing javascript lib to extract param's value in the querystring.

like image 93
Ray Lu Avatar answered Sep 21 '22 10:09

Ray Lu