working with Query String in GWT

我的梦境 提交于 2020-01-11 05:36:10

问题


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.


回答1:


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.




回答2:


@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.




回答3:


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;
}



回答4:


There is in-built support for getting all of the parameters.

Simply call:

     Map<String, List<String>> parameterMap = Window.Location.getParameterMap();


来源:https://stackoverflow.com/questions/6261529/working-with-query-string-in-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!