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:
trying to use jsp:UseBean fails to work, as it won't let me declare it either as an ArrayList or an ArrayList-String.
trying to use JSTL and EL doesn't work, as the renderer completely ignores my ${articleList}.
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?
My controller:
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);
}
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WSD Newspaper</title>
</head>
<body>
<%@ include file="WEB-INF/login_fragment.jsp" %>
<%@ include file="WEB-INF/header.jsp" %>
<span id="articles">
<c:forEach var="article" items="${articleList}">
<span class="article">
<h1>${article.title}</h1>
<div class="byline">by ${article.author.name}</div>
<p class="short-text"> ${article.shortText}</p>
<p><a href="article/${article.id}">Read More...</a></p>
</span>
</c:forEach>
</span>
</body>
</html>