Java URL Parameter Builder getUrlParameters(String url)

Here you can find the source of getUrlParameters(String url)

Description

get Url Parameters

License

LGPL

Declaration

public static Map<String, LinkedList<String>> getUrlParameters(String url) throws Exception 

Method Source Code


//package com.java2s;
//License from project: LGPL 

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

public class Main {
    public static Map<String, LinkedList<String>> getUrlParameters(String url) throws Exception {
        Map<String, LinkedList<String>> params = new HashMap<String, LinkedList<String>>();

        if (url == null) {
            return params;
        }/* w w  w  .  j  a v  a 2 s  . c o  m*/

        String query;
        String[] urlParts = url.split("\\?");
        if (urlParts.length > 1) {
            query = urlParts[1];
        } else if (url.indexOf("=") >= 0) {
            query = url;
        } else {
            query = "";
        }

        for (String param : query.split("&")) {
            String pair[] = param.split("=");
            String key = URLDecoder.decode(pair[0], "UTF-8");
            String value;
            if (pair.length > 1) {
                value = URLDecoder.decode(pair[1], "UTF-8");
            } else {
                value = null;
            }
            LinkedList<String> values = params.get(key);
            if (values == null) {
                values = new LinkedList<String>();
                params.put(key, values);
            }
            values.add(value);
        }

        return params;
    }
}

Related

  1. format(Map parameters, final String encoding)
  2. getParameter(String source, int index)
  3. getParameterMap(byte[] bytea)
  4. getParams(String str)
  5. getUrlParameters(final String url)
  6. getUrlParameters(String url)
  7. getUrlParameters(String url)
  8. getUrlParameters(String url)
  9. getUrlParameters(String url)