Java URL Query Split splitQuery(URL url)

Here you can find the source of splitQuery(URL url)

Description

split Query

License

Open Source License

Declaration

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

Method Source Code

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

import java.net.URL;

import java.net.URLDecoder;

import java.util.*;
import java.io.UnsupportedEncodingException;

public class Main {
    public static Map<String, String> splitQuery(URL url) throws UnsupportedEncodingException {
        Map<String, String> queryPairs = new LinkedHashMap<String, String>();
        String query = url.getQuery();
        String[] pairs = query.split("&");
        for (String pair : pairs) {
            int idx = pair.indexOf("=");
            String key = URLDecoder.decode(pair.substring(0, idx), "UTF-8");
            if (queryPairs.get(key) == null) {
                queryPairs.put(key, URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
            } else {
                queryPairs.put(key,//from   ww w .ja va2s  . c om
                        queryPairs.get(key) + ", " + URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
            }
        }
        return queryPairs;
    }
}

Related

  1. splitQuery(String query)
  2. splitQuery(String query)
  3. splitQuery(String queryString)
  4. splitQuery(String url)
  5. splitQuery(URL url)