title: What's the best way to use an ArrayList of objects in a JSP page?
body: <p>I'm trying to have my JSP page cleanly go through an ArrayList of data objects, and for each one, insert the contents into a piece of HTML. Even for a simple page, it fails to work correctly. I'm placing the ArrayList into the HttpServletRequest object as an attribute, but:</p>
  
  <ul>
  <li><p>trying to use jsp:UseBean fails to work, as it won't let me declare it either as an ArrayList or an ArrayList-String.</p></li>
  <li><p>trying to use JSTL and EL doesn't work, as the renderer completely ignores my ${articleList}.</p></li>
  </ul>
  
  <p>I'm clearly doing something wrong, but I'm not sure what. Have I misconfigured JSTL and EL? Am I using something way too complex to do something that could be more easily achieved another way?</p>
  
  <p>My controller:</p>
  
  <pre><code>public void doGet(  HttpServletRequest request,
              HttpServletResponse response) 
              throws ServletException, IOException {
          //index
          if (request.getContextPath() == "") {
              request.setAttribute("articleList", getArticles());
              RequestDispatcher dp = request.getRequestDispatcher("/index.jsp");
              dp.forward(request, response);
          }
  
          RequestDispatcher dp = request.getRequestDispatcher("/404.html");
          dp.forward(request, response);
      }
  </code></pre>
  
  <p>index.jsp:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;WSD Newspaper&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;%@ include file="WEB-INF/login_fragment.jsp" %&gt;
      &lt;%@ include file="WEB-INF/header.jsp" %&gt;
  
  &lt;span id="articles"&gt;
      &lt;c:forEach var="article" items="${articleList}"&gt;
      &lt;span class="article"&gt;
          &lt;h1&gt;${article.title}&lt;/h1&gt;
          &lt;div class="byline"&gt;by ${article.author.name}&lt;/div&gt;
          &lt;p class="short-text"&gt; ${article.shortText}&lt;/p&gt;
          &lt;p&gt;&lt;a href="article/${article.id}"&gt;Read More...&lt;/a&gt;&lt;/p&gt;
      &lt;/span&gt;
      &lt;/c:forEach&gt;
  &lt;/span&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>