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 JavaScript making 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{
////Code to be handeled where response is recieved
}catch(e){
alert(e);
}
}
On making this request I try to retrieve the parameters sent from JavaScript in a Servlet, but while doing so I was firstly confused on how to retrieve the dat from the request
I used the following in my servlet:
NOTE : the content Type in my Servlet is set to : apllication/json
response.setContentType("application/json");
request.getParameterMap();
the above showed me the data as below, but I was not able 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 Exception of null which was expected.
request.getParametervalues("items");
Among the others i tried where request.getParameter(); request.getParameterNames(); but in vain...
Am I in a wrong direction? Please guide me!
Please let me know how to retieve these value.
Thank You for reading this long post...
Sangeet
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…