title: Springs MVC JSON Response and convert it to JS Object
body: <p>I am having a question that how can I send JSON Object from Springs MVC so that I can convert it into a JavaScript Object on my HTML Page.</p>
  
  <p>In a traditional way I do it: Below is a snippet from Java Servlet which sets a request attribute and forward it to the JSP Page.</p>
  
  <pre><code>   JSONObject jsonObj = new JSONObject();
     jsonObj.put("name","test");
     jsonObj.put("age",24);
     request.setAttribute("jsonObj",jsonObj);
     request.getRequestDispatcher("test.jsp").forward(request,response);
  </code></pre>
  
  <p>In JSP I retrieve as :</p>
  
  <pre><code>   &lt;script type="text/javascript"&gt;
      var jsonObj =&lt;%=request.getAttribute("jsonObj"); %&gt;;
      alert("name = "+jsonObj.name+" ; age = "+jsonObj.age); // This will output name and age from the JSON Object
     &lt;/script&gt;
  </code></pre>
  
  <p>So what I need to ask how can I do the same in Springs MVC. How can I send the JSONObject from Dispatcher Servlet, and convert it to JS object in my JSP page ?</p>