title: How to access a servlet variable inside javascript
body: <p>I have a servlet which has a variable which holds a JSON string.</p>
  
  <pre><code>JSONObject obj = new JSONObject();
  obj.put("parameter", jsonList);
  request.setAttribute("jsonstring", obj.toString());
  RequestDispatcher rd = request.getRequestDispatcher("/file.jsp");
  rd.forward(request, response);
  </code></pre>
  
  <p>Now I am forwarding my request and response objects to a JSP page which contains a JS file.
  How can I access the value of <b>jsonstring</b> variable inside the JS file.As I need to parse my JSON string further using jQuery.</p>
  
  <p>I tried doing this in my JS file as I saw in some of the posts online.But it seems like its not working for me.</p>
  
  <pre><code>var test = '&lt;%=request.getAttribute("jsonstring")%&gt;'
  </code></pre>
  
  <p>Kindly guide me on the same.Thanx.</p>