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) 

Method Source Code


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

import java.io.*;

import java.net.URLDecoder;

import java.util.*;

public class Main {
    public static Map<String, String> getUrlParameters(String url) {
        Map<String, String> params = new HashMap<String, String>();
        String[] urlParts = url.split("\\?");
        String query = "";
        if (urlParts.length > 0) {
            query = urlParts[0];//from  w ww . j av a 2s .co m
        }
        if (urlParts.length > 1) {
            query = urlParts[1];
        }
        if (!query.equals("")) {
            for (String param : query.split("&")) {
                String pair[] = param.split("=");
                try {
                    String key = URLDecoder.decode(pair[0], "UTF-8");
                    String value = "";
                    if (pair.length > 1) {
                        value = URLDecoder.decode(pair[1], "UTF-8");
                    }
                    params.put(key, value);
                } catch (UnsupportedEncodingException ex) {
                    //ignore, fuck you java
                }
            }
        }
        return params;
    }
}

Related

  1. getParams(String str)
  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)
  9. map2String(Map params)