title: Getting the json array from servlet to javascript variable
body: <p>I have a java servlet that sends a json object to a jsp page in a javascript variabile with array format.</p>
  
  <p>Here is my servlet ( a part of it): </p>
  
  <pre><code>List&lt;HistoryLeavesScalar&gt; returnedPastInfo = SaveDAO.getPastInformation(username);
  JSONArray jsonArray = new JSONArray(returnedPastInfo);
  String s = jsonArray.toString();
  System.out.println("\n\n"+"JSON ARRAY is :  "+s);
  
  HttpSession session = request.getSession(true);
  session.setAttribute("jsonArray",jsonArray); 
  this.getServletContext().getRequestDispatcher("/calendar.jsp")
  .forward(request, response);
  </code></pre>
  
  <p>that system.out.print JSON is something like this in my console: 
  [{"endDate":"2017-04-22","req":"2017-04-19","nr":2,"type":"CO","startDate":"2017-04-20","Dep":"2017-04-19"},{"endDate":"2017-04-22","req":"2017-04-20","nr":3,"type":"CM","startDate":"2017-04-20","Dep":"2017-04-19"}]</p>
  
  <p>This Json Array I want to be visible in javascript tag like this in that format only: ( this is calendar.jsp - a part of it)</p>
  
  <pre><code>    &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %&gt;
      &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt; 
      &lt;%@ page import="javax.servlet.jsp.jstl.core.*"%&gt;
      &lt;%@ page import="javax.servlet.jsp.el.*" %&gt; 
      &lt;%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%&gt;
  &lt;script type="text/javascript"&gt;
  
      var USER_DAYS   =   [
                  &lt;c:forEach items="${jsonArray}" var="jsonArray"&gt;
  
  
                          {
                              id: '${jsonArray.nr}',
                              date: '${jsonArray.req}',
                              title: '${jsonArray.type}',
                              startDate: '${jsonArray.startDate',
                              endDate: '${jsonArray.endDate',
                              allDay: true,
                              className: 'done'
                          }
                 &lt;/c:forEach&gt;
      ];
  &lt;/script&gt;
  </code></pre>
  
  <p>I don't know how to access the values from that json that comes from the servlet in USER_DAYS variable (javascript). How to put the values from json in id, date, title, startDate, endDate.</p>
  
  <p>I don't know if jstl works in a javascript tag. I don't know how to print that values ( whatever they are - it can contain many information, all in that format).</p>
  
  <p>I want to mention that, if I change the javascript variable into somthing like this: it works just fine. But these are values which I have handwritten, but now I want them dynamically...and this information must come from servlet into calendar.jsp.</p>
  
  <pre><code>var USER_DAYS   =   [
        {
            id: 1,
            date: '2017-04-05',
            title: 'CO',
            start: new Date(2017, 3, 5),
            end: new Date(2017, 3, 7),
            allDay: true,
            className: 'done'
        },
  </code></pre>
  
  <p>Can someone help  me?</p>