title: passing json data from servlet to jsp to js file
body: <p>I got this servlet which creates JSON data and I want to pass this data on to a jsp page which is supposed to display the data via the InfoVis toolkit.</p>
  
  <p>servlet.java</p>
  
  <pre><code>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 &lt; 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);
  </code></pre>
  
  <p>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.</p>
  
  <p>graph.jsp</p>
  
  <pre><code>&lt;body onload="init('${jsonString}');"&gt;
  </code></pre>
  
  <p>spacetree.js</p>
  
  <pre><code>function init(jsonString){
  
      var json = jsonString;
  </code></pre>
  
  <p>Originally the function call is only </p>
  
  <pre><code>&lt;body onload="init()"&gt;
  </code></pre>
  
  <p>but the init() function has the JSON variable hardcoded, which is of course not useful at all. So I'm looking for a way to make that dynamic. But since theres quotations inside the string it now totally messes up the onload=init() function call..</p>