title: pass String from Java servlet to jsp to js
body: <p>I want to pass a String from a Servlet to a jsp page, where it has to be passed on to a init function that resides in an external .js. That's what I got so far:</p>
  
  <p><strong>servlet</strong></p>
  
  <pre><code>request.setAttribute("jsonString", json.toString());
  RequestDispatcher dispatcher = request.getRequestDispatcher("graph.jsp");
  dispatcher.forward(request, response);
  </code></pre>
  
  <p><strong>jsp</strong></p>
  
  <pre><code>&lt;body onload="init('&lt;%= request.getParameter("jsonString") %&gt;');"&gt;
  </code></pre>
  
  <p><strong>js</strong></p>
  
  <pre><code>function init(jsonString){
  
      var json = jsonString;
  </code></pre>
  
  <p>Unfortunately the only thing I receive in the init function is null. I made sure that json.toString() returns the correct value. So it must get lost between the forwarding and the init function. What is the correct way to do this?</p>