Java URL Query Build getQueryParameters(URL url)

Here you can find the source of getQueryParameters(URL url)

Description

get Query Parameters

License

Open Source License

Declaration

public static Map<String, String> getQueryParameters(URL url) 

Method Source Code


//package com.java2s;
/*//from ww w.jav  a  2s .  com
 * This is a program for Language Grid Core Node. This combines multiple language resources and provides composite language services.
 * Copyright (C) 2008-2010 NICT Language Grid Project.
 *
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation, either version 2.1 of the License, or (at 
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.UnsupportedEncodingException;

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

public class Main {
    /**
     * 
     * 
     */
    public static Map<String, String> getQueryParameters(URL url) {
        Map<String, String> params = new HashMap<String, String>();
        String q = url.getQuery();
        if (q == null)
            return params;

        try {
            for (String p : q.split("&")) {
                String[] values = p.split("=", 2);
                if (values.length != 2)
                    continue;
                params.put(URLDecoder.decode(values[0], "UTF-8"), URLDecoder.decode(values[1], "UTF-8"));
            }
        } catch (UnsupportedEncodingException e) {
            // Java must support "UTF-8"
            throw new RuntimeException(e);
        }
        return params;
    }
}

Related

  1. getQueryMap(URL url)
  2. getQueryParameter(String query, String key, String encoding)
  3. getQueryParameterMap(String queryString)
  4. getQueryParameters(URL url)
  5. getQueryParameters(URL url)
  6. getQueryParametersFromUrl(String url)
  7. getQueryParams(String httpUrl)
  8. getQueryParams(String query)
  9. getQueryParams(String s)