I think this is the servlet code you are looking for, but I think you would need to first convert the Student
object to the JSONObject
and then put the JSONObject
s in JSONArray
, this tutorial might help you:
JSONObject js = new JSONObject();
org.json.JSONArray jsonArray = new JSONArray(list);
// set the response content-type
response.setContentType("application/json");
PrintWriter out = response.getwriter();
// writing the json-array to the output stream
out.print(jsonArray);
out.flush();
In the javascript method the data
in function(data)
would contain this json-array and you can use this answer to get the data in your html page.