Here you can find the source of getQueryParams(String s)
Parameter | Description |
---|---|
s | The query string |
Parameter | Description |
---|---|
MalformedURLException | If the query string is malformed. |
public static Map<String, String> getQueryParams(String s) throws MalformedURLException
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.*; import java.util.HashMap; import java.util.Map; public class Main { /**/*from w ww. j a v a2 s. co m*/ * Get traditional query parameters as a Java map * @param s The query string * @return A Java map with key-value pairs derived from the query string * @throws MalformedURLException If the query string is malformed. */ public static Map<String, String> getQueryParams(String s) throws MalformedURLException { Map<String, String> params = new HashMap<String, String>(); for (String kv : s.split("&")) { String[] parts = kv.split("="); if (parts.length != 2) { throw new MalformedURLException(); } try { String k = URLDecoder.decode(parts[0], "UTF-8"); String v = URLDecoder.decode(parts[1], "UTF-8"); params.put(k, v); } catch (UnsupportedEncodingException ex) { throw new MalformedURLException(ex.getMessage()); } } return params; } }