Following is sample HTTP POST request which is sent to servlet.
//create javascript object
var customer = [];
customer.push({
"customerID": "123",
"customerName": "Name One",
"city": "City One",
});
customer.push({
"customerID": "124",
"customerName": "Name Two",
"city": "City Two",
});
//request to servlet
$.post('MyServletName',{ "customer":customer }).done(function(data) { alert(data); });
Question is how to access the customer object in servlet?
I have tried following way:
Way 1:
request.getParameterValues("customer") //returns null
Way 2:
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String key = (String) parameterNames.nextElement();
String val = request.getParameter(key);
System.out.println(key+": "+val);
}
output:
customer[1][city]: City Two
customer[1][customerID]: 124
customer[0][city]: City One
customer[0][customerID]: 123
customer[1][customerName]: Name Two
customer[0][customerName]: Name One