Java URL Query Parse parseQueryString(String q, String enc)

Here you can find the source of parseQueryString(String q, String enc)

Description

parse Query String

License

Open Source License

Declaration

public static Map parseQueryString(String q, String enc)
            throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/*/*from   w w  w  .j  a  v a  2 s. c  om*/
 * B3P Commons Core is a library with commonly used classes for webapps.
 * Included are clieop3, oai, security, struts, taglibs and other
 * general helper classes and extensions.
 *
 * Copyright 2000 - 2008 B3Partners BV
 * 
 * This file is part of B3P Commons Core.
 * 
 * B3P Commons Core is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * B3P Commons Core 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with B3P Commons Core.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Map;
import java.util.Hashtable;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Main {
    public static Map parseQueryString(String q, String enc)
            throws UnsupportedEncodingException {
        String[] params = q.split("&");

        Map results = new Hashtable(params.length);

        for (int i = 0; i < params.length; i++) {
            String[] kv = params[i].split("=", 2);
            results.put(URLDecoder.decode(kv[0], enc),
                    kv.length > 1 ? URLDecoder.decode(kv[1], enc) : "");
        }

        return results;
    }
}

Related

  1. parseQueryParameters( String queryString, String encoding)
  2. parseQueryString(final String newQueryString, final String encoding)
  3. parseQueryString(String input)
  4. parseQueryString(String path)
  5. parseQueryString(String path)
  6. parseQueryString(String query)
  7. parseQueryString(String query)
  8. parseQueryString(String query, boolean ignoreEmpty)
  9. parseQuerystring(String queryString)