Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

working with Query String in GWT

I have to created a dynamic URLcontaining the user id and email parameters, which will direct to sign up form in my GWT application. I want to set and get the parameters in the query string. I have referred tp http://code.google.com/p/gwt-examples/source/browse/trunk/System/src/com/gawkat/gwt/system/client/global/QueryString.java?r=1241 but here QueryStringData is inaccessible to my project.Please tell me how I can do it? Any alternative could also help me.

like image 944
Amandeep Singh Avatar asked Jun 07 '11 06:06

Amandeep Singh


People also ask

What is query string in GET request?

The QueryString collection is a parsed version of the QUERY_STRING variable in the ServerVariables collection. It enables you to retrieve the QUERY_STRING variable by name. The value of Request. QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING.

How does a query string work?

A query string is a set of characters tacked onto the end of a URL. The query string begins after the question mark (?) and can include one or more parameters. Each parameter is represented by a unique key-value pair or a set of two linked data items. An equals sign (=) separates each key and value.

What is Google query string?

Query strings are often called parameters because they are used to pass parameters to code that runs on a landing page. Learn more about passing parameters to keyword landing pages from keyword landing page URLs in Search Ads 360.

What is query string in REST API?

The "query string" is defined as a question mark followed by the parameters and their values. Each parameter is listed one after the other in the query string, separated by an ampersand (&). It makes no difference what order the query string parameters are in.


3 Answers

@Stein, but there is (a query parameter tokenizer in GWT): e.g. Window.Location.getParameter("debug") will return the string value of the parameter debug.

like image 200
Boris Brudnoy Avatar answered Oct 04 '22 03:10

Boris Brudnoy


Don't think there's a simple tokenized query string parser in GWT. But you can get the raw query string by using:

String queryString = Window.Location.getQueryString();

Parse it any way you like. I use it like this to set debug flags etc.:

boolean debugMode = Window.Location.getQueryString().indexOf("debug=true") >= 0;

Note that changing values in the query part of the url (between the ? and the #) will reload the page. While changing the "hash part" of the url (anything after the #) will not reload the page. Which is why the com.google.gwt.user.client.History uses the hash part.

like image 21
Stein G. Strindhaug Avatar answered Oct 04 '22 03:10

Stein G. Strindhaug


If you want really want to parse the history token (hash part) to encode parameters, here's the code for that:

private static Map<String, String> buildHashParameterMap() {
    final String historyToken = History.getToken();
    Map<String, String> paramMap = new HashMap<String, String>();
    if (historyToken != null && historyToken.length() > 1) {
        for (String kvPair : historyToken.split("&")) {
            String[] kv = kvPair.split("=", 2);
            if (kv.length > 1) {
                paramMap.put(kv[0], URL.decodeQueryString(kv[1]));
            } else {
                paramMap.put(kv[0], "");
            }
        }
    }

    return paramMap;
}
like image 20
Ryan Shillington Avatar answered Oct 04 '22 04:10

Ryan Shillington