I have a query on retrieving data sent as JSON from a JavaScript, inside a Java servlet. Following is what I am doing...
This is the part of the code inside JavaScr
The request parameter map is a Map<String, String[]>
where the map key is the parameter name and map value are the parameter values --HTTP allows more than one value on the same name.
Given the printout of your map, the following should work:
String item0Name = request.getParameter("items[0][name]");
String item0Time = request.getParameter("items[0][time]");
String item1Name = request.getParameter("items[1][name]");
String item1Time = request.getParameter("items[1][time]");
If you want a bit more dynamics, use the following:
for (int i = 0; i < Integer.MAX_VALUE; i++) {
String itemName = request.getParameter("items[" + i + "][name]");
String itemTime = request.getParameter("items[" + i + "][time]");
if (itemName == null) {
break;
}
// Collect name and time in some bean and add to list yourself.
}
Note that setting the response content type is irrelevant when it comes to gathering the request parameters.