Java URL Query Build getQueryValues(String input)

Here you can find the source of getQueryValues(String input)

Description

get Query Values

License

Apache License

Declaration

public static Map<String, String> getQueryValues(String input) 

Method Source Code


//package com.java2s;
/*/*from   w ww  .j a  v  a  2  s.c om*/
 * Copyright 2004 - 2012 Cardiff University.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static Map<String, String> getQueryValues(String input) {

        Map<String, String> ret = new HashMap<String, String>();
        String[] params = input.split("&");
        for (String param : params) {
            try {
                int eq = param.indexOf("=");
                if (eq > 0) {
                    String key = param.substring(0, eq);
                    String value = param.substring(eq + 1, param.length());
                    value = URLDecoder.decode(value, "UTF-8");
                    ret.put(key, value);
                }
            } catch (UnsupportedEncodingException e) {

            }
        }
        return ret;

    }
}

Related

  1. getQueryString(Map parameters)
  2. getQueryString(String url)
  3. getQueryUrl(String word)
  4. getQueryUrl(String word, Integer page)
  5. getQueryURL(URL baseUrl, String[] parameters)
  6. mapToQueryString(Map parameters, String charSet)
  7. mapToQueryString(Map parameters, String charSet)
  8. mapToQueryString(Map queryString)
  9. toQueryString(Map map)