title: How to set jsp variable in java script array?
body: <p>Hi I am trying to set jsp variable into a javascript array. I tried, but I am not able to achieve this when I run my code. I do not get my output, I only see a blank screen.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>value.jsp</strong></p>
  
  <pre><code>&lt;script&gt;
               &lt;%
  
         URL url;
           ArrayList&lt;String&gt; list1 = new ArrayList&lt;String&gt;();
              ArrayList&lt;String&gt; list2 = new ArrayList&lt;String&gt;();
             List commodity = null;
             List pric = null;
             int c = 0;
             int p = 0;
  
       try {
              // get URL content
  
              String a = "http://122.160.81.37:8080/mandic/commoditywise?c=paddy";
              url = new URL(a);
              URLConnection conn = url.openConnection();
              // open the stream and put it into BufferedReader
              BufferedReader br = new BufferedReader(
                                 new InputStreamReader(conn.getInputStream()));
              StringBuffer sb = new StringBuffer();
              String inputLine;
              while ((inputLine = br.readLine()) != null)
     {
                      System.out.println(inputLine);
                    //  sb.append(inputLine);
                     String s=inputLine.replace("|", "\n");
                     s = s.replace("~"," ");
                     StringTokenizer str = new StringTokenizer(s);
                      while(str.hasMoreTokens())
  
     {
         String mandi = str.nextElement().toString();
         String price = str.nextElement().toString();
         list1.add(mandi);
         list2.add(price);
     }
  
     }
  
         commodity = list1.subList(0,10);
                           pric = list2.subList(0,10);
                           for (c = 0,p = 0; c &lt; commodity.size()&amp;&amp; p&lt;pric.size(); c++,p++) 
              {
                  String x = (String)commodity.get(c);
                  String y = (String)pric.get(p);
                  //out.println(y);
                  //out.println(x);}
               %&gt;
  
  
  
       jQuery(function ($) {
      var roles = []; 
       roles.push(&lt;%= x%&gt;)  
       roles.push(&lt;%= y%&gt;)  
       &lt;%
  
              }
       %&gt;
  
      var counter = 0;
      var $role = $('#role')
      //repeat the passed function at the specified interval - it is in milliseconds
      setInterval(function () {
          //display the role and increment the counter to point to next role
          $role.text(roles[counter++]);
          //if it is the last role in the array point back to the first item
          if (counter &gt;= roles.length) {
              counter = 0;
          }
      }, 400)
      });
  
      &lt;/script&gt;
  
              &lt;%
  
       br.close();
  
              //System.out.println(sb);
  
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }  
  
      %&gt;
  </code></pre>
  
  <p>How can I achieve my desired output?</p>