GWT - How to get parameters from the URL

Question:
Are you in the position that the simple URL that launches your application needs more information? like some extra parameters that we add usualy in any WEB application,

i.e.  h t t p : / / mysite . com ? parm1 = val1 & parm2 = val2
(spaces are added here to avoid having this example like a real clickable link).

So, how do we get this information within our GWT module / application ?

Answer:
 is quite simple, and it's present in the below helper static native function:

/**
* Gets the string with the parameters from the current URL.
*
* @return String containing the list of parameters from the URL
* in format: ?aaa=bbbb&vvvv=ccc
*/
public static native String getParamString() /*-{
     return $wnd.location.search;
}-*/;


So, the result of this is a string in the format "?parm1=val1&parm2=val2", which won't be a problem to parse and extract the list or parameters and their values, right ?

Cheers!

No comments:

Post a Comment