working with Query String in GWT

前端 未结 4 797
闹比i
闹比i 2021-01-13 06:23

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

相关标签:
4条回答
  • 2021-01-13 06:36

    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;
    }
    
    0 讨论(0)
  • 2021-01-13 06:44

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

    Simply call:

         Map<String, List<String>> parameterMap = Window.Location.getParameterMap();
    
    0 讨论(0)
  • 2021-01-13 06:45

    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.

    0 讨论(0)
  • 2021-01-13 06:52

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

    0 讨论(0)
提交回复
热议问题