I have below sample map arraylist. First, how do i access this arraylist from inside a pure html using javascript? Second, how do i iterate over this list?
<%@page import="org.json.simple.JSONObject"%>
<%@page import="org.json.simple.JSONArray"%>
<%
JSONObject json = new JSONObject();
JSONArray list = new JSONArray();
JSONObject course1,course2,course3,course4,course5;
course1 = new JSONObject();
course1.put("code", "ME101");
course1.put("desc", "Marine Engineering 101");
course1.put("sched", "June 1 - August 30, 2014");
course1.put("rsvd", "56");
course1.put("crssched", "cme101s1");
list.add(course1);
course2 = new JSONObject();
course2.put("code", "ME102");
course2.put("desc", "Marine Engineering 102");
course2.put("sched", "September 1 - November 31, 2014");
course2.put("rsvd", "25");
course2.put("crssched", "cme102s1");
list.add(course2);
course3 = new JSONObject();
course3.put("code", "CS101");
course3.put("desc", "Certificate on Seamanship 101");
course3.put("sched", "June 1 - June 30, 2014");
course3.put("rsvd", "36");
course3.put("crssched", "ccs101s1");
list.add(course3);
course4 = new JSONObject();
course4.put("code", "ME201");
course4.put("desc", "Marine Engineering 201");
course4.put("sched", "June 15 - July 16, 2014");
course4.put("rsvd", "65");
course4.put("crssched", "cme201s1");
list.add(course4);
course5 = new JSONObject();
course5.put("code", "ME202");
course5.put("desc", "Marine Engineering 202");
course5.put("sched", "July 1 - August 30, 2014");
course5.put("rsvd", "15");
course5.put("crssched", "cme202s1");
list.add(course5);
json.put("Courses", list);
response.setContentType("application/json");
response.getWriter().write(json.toString());
The scenario is that i have html-only files in the webserver and i get data from jsp files on another server which i need to display in a table to the html files using javascript or jquery.
Any ideas?
EDIT
Based on user13500's suggestion, I have looked into JSON and updated the sample data above. Tested it to write on the page and it does print out the key value pairs.
How do I now "expose" the json object and access it from another html page?
List<Map<String, String>> listisn't Javascript.JSON.parse(reply)in Javascript.)list.toString()instead ofjson.put("Courses", list); and json.toString()if (typeof responseData === "string") { responseData = JSON.parse(responseData); }