I am trying to create a simple REST web-server. The actual URL looks like this
The first ID is the ID of the requested file,the number of person in the parameter is not know in advance. I want to group this person in a collection/map.
It's not mandatory for the URL to be structured in this way. I could also use this URL if it could make it easier
I tried to adapt these codes but as a newbie it I got really confused.
This is my code
System.out.println(query);
final Map<String, List<String>> query_pairs = new LinkedHashMap<String, List<String>>();
final String[] pairs = query.split("&");
for (String pair : pairs) {
final int idx = pair.indexOf("=");
final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
if (!query_pairs.containsKey(key)) {
query_pairs.put(key, new LinkedList<String>());
}
final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : null;
query_pairs.get(key).add(value);
System.out.println(query_pairs);
And this is the output I got
{id=[23?firstname1=alex]}
{id=[23?firstname1=alex], lastname1=[ozouf]}
{id=[23?firstname1=alex], lastname1=[ozouf], age1=[23?firstname=kevin]}
{id=[23?firstname1=alex], lastname1=[ozouf], age1=[23?firstname=kevin], lastname=[gefild?age=22]}