Java URL Query Parse parseQueryString(String input)

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

Description

parse Query String

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*/*from  w ww .  j  a  va2 s  . c  o  m*/
 FatRat download manager
 http://fatrat.dolezel.info

 Copyright (C) 2006-2011 Lubos Dolezel <lubos a dolezel.info>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.

 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 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

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

import java.util.HashMap;
import java.util.Map;

public class Main {
    public static Map<String, String> parseQueryString(String input) {
        try {
            Map<String, String> rv = new HashMap<String, String>();
            String[] parts = input.split("&");

            for (String part : parts) {
                String[] pair = part.split("=", 2);
                if (pair.length != 2)
                    continue;

                String name = URLDecoder.decode(pair[0], "UTF-8");
                String value = URLDecoder.decode(pair[1], "UTF-8");

                rv.put(name, value);
            }

            return rv;
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }
}

Related

  1. parseQuery(String query)
  2. parseQuery(String queryString)
  3. parseQueryParameters( String query)
  4. parseQueryParameters( String queryString, String encoding)
  5. parseQueryString(final String newQueryString, final String encoding)
  6. parseQueryString(String path)
  7. parseQueryString(String path)
  8. parseQueryString(String q, String enc)
  9. parseQueryString(String query)