title: How to display values of an ArrayList that is defined in the JSP itself, using JSTL
body: <p>I have an ArrayList that is defined in a scriptlet in a JSP. In the body section, I want to display the items using a JSTL forEach loop.</p>
  
  <p>After going through tutorials like <a href="http://www.java2s.com/Tutorial/Java/0380__JSTL/UseForEachtoLoopThroughArrayList.htm" rel="nofollow">this one</a>, I have written the following code:</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;%@ page import="java.util.ArrayList" %&gt;
  
  &lt;%
  ArrayList&lt;String&gt; fruits = new ArrayList&lt;String&gt;();
  fruits.add("Orange");
  fruits.add("Apple");
  %&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;JSTL&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;c:forEach var="fruit" items="${fruits}"&gt;
          &lt;c:out value="${fruit}" /&gt;
      &lt;/c:forEach&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But I am getting a blank page. Where am I going wrong in the above code?</p>
  
  <p>All tutorials that I could find seem to define an ArrayList of beans in the servlet and pass them to the JSP through the <code>request</code>. In the forEach loop, they use <code>c:out</code> and <code>${bean.prop}</code> to print it. I haven't tried them as such. I wanted to do something much simpler, but can't seem to get this code to work.</p>