Java EE has ServletRequest.getParameterValues().
On non-EE platforms, URL.getQuery() simply returns a string.
What\'s the normal way to properly parse the qu
Just for reference, this is what I've ended up with (based on URLEncodedUtils, and returning a Map).
Features:
request.getQueryString())MapListCode:
public static Map> getParameterMapOfLists(String queryString) {
Map> mapOfLists = new HashMap>();
if (queryString == null || queryString.length() == 0) {
return mapOfLists;
}
List list = URLEncodedUtils.parse(URI.create("http://localhost/?" + queryString), "UTF-8");
for (NameValuePair pair : list) {
List values = mapOfLists.get(pair.getName());
if (values == null) {
values = new ArrayList();
mapOfLists.put(pair.getName(), values);
}
if (pair.getValue() != null) {
values.add(pair.getValue());
}
}
return mapOfLists;
}
A compatibility helper (values are stored in a String array just as in ServletRequest.getParameterMap()):
public static Map getParameterMap(String queryString) {
Map> mapOfLists = getParameterMapOfLists(queryString);
Map mapOfArrays = new HashMap();
for (String key : mapOfLists.keySet()) {
mapOfArrays.put(key, mapOfLists.get(key).toArray(new String[] {}));
}
return mapOfArrays;
}