I got this servlet that creates JSON data, and I want to transfer this data to a jsp page that should display the data using InfoVis tools.
servlet.java
JSONObject json = new JSONObject(); JSONArray toplevel = new JSONArray(); JSONObject sublevel; try{ json.put("id", "node" + 0); json.put("name", "name" + 0); int count = 5; for(int i=1; i < count; i++){ sublevel = new JSONObject(); sublevel.put("id", "node" + i); sublevel.put("name", "name" + i); toplevel.put(sublevel); } json.put("children", toplevel); } catch (JSONException jse) { } request.setAttribute("jsonString", json.toString()); RequestDispatcher dispatcher = request.getRequestDispatcher("graph.jsp"); dispatcher.forward(request, response);
The following code is provided by the InfoVis Toolkit, and I'm not sure if it can be changed. Or at least I don't have enough experience in JS to change it.
graph.jsp
<body onload="init('${jsonString}');">
spacetree.js
function init(jsonString){ var json = jsonString;
Initial function call only
<body onload="init()">
but the init () function has a JSON hardcoded variable, which, of course, is not useful at all. Therefore, I am looking for a way to make this dynamic. But since theres quotes inside the line now completely messed up the onload = init () function call ..
source share