Java URL Parameter Builder getUrlParameters(String url)

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

Description

get Url Parameters

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.net.URLDecoder;

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static Map<String, String> getUrlParameters(String url) throws UnsupportedEncodingException {
        Map<String, String> params = new HashMap<>();
        String query = url.substring(url.indexOf("?") + 1);
        for (String param : query.split("\n\t")) {
            String pair[] = param.split("=");
            if (pair.length < 2)
                continue;
            String key = URLDecoder.decode(pair[0].replaceAll("&", ""), "utf-8");
            String value = "";
            if (pair.length > 1) {
                try {
                    value = URLDecoder.decode(pair[1], "utf-8");
                } catch (Exception e) {
                    value = pair[1];/*  w  w  w.  j  a  va2  s .c o  m*/
                }
            }
            if (key != null && !key.trim().isEmpty())
                params.put(key.toLowerCase(), value);
        }
        return params;
    }
}

Related

  1. format(Map parameters, final String encoding)
  2. getUrlParameters(final String url)
  3. getUrlParameters(String url)
  4. getUrlParameters(String url)
  5. getUrlParameters(String url)
  6. getUrlParameters(String url)
  7. getUrlParameters(String url)
  8. getURLParameters(URI uri)