I have a request to receive data sent as JSON from JavaScript inside a Java servlet. The following is what I do ...
This is part of the code inside JavaScript that makes a request to a servlet
type : "POST", url: 'getInitialData', datatype: 'json', data : ({items :[{ name: "John", time: "2pm" },{name: "Sam", time: "1pm" }]}), success: function(data) { try{
While executing this request, I try to get parameters sent from JavaScript to Servlet, but at the same time I was confused at first with how to get data from the request
In my servlet, I used the following:
NOTE. . The content type in my servlets is set to: apllication / json
response.setContentType("application/json"); request.getParameterMap();
the above showed me the data as below, but I could not figure out how to work and get the actual data.
{items[1][name]=[Ljava.lang.String;@1930089, items[0][time]=[Ljava.lang.String;@860ba, items[1][time]=[Ljava.lang.String;@664ca, items[0][name]=[Ljava.lang.String;@1c334de}
while the following code gave me a null value exception that was expected.
request.getParametervalues("items");
Among others, I tried where request.getParameter (); request.getParameterNames (); but in vain ...
Am I in the wrong direction? Please guide me! Please let me know how to return this value.
Thanks for reading this long post ...
Sangit