在JSP页面中使用对象数组列表的最佳方式是什么?

在JSP页面中使用对象数组列表的最佳方式是什么?,jsp,jstl,el,Jsp,Jstl,El,我试图让我的JSP页面干净地遍历数据对象的ArrayList,并将每个数据对象的内容插入到一段HTML中。即使是一个简单的页面,它也无法正常工作。我将ArrayList作为属性放入HttpServletRequest对象中,但是: 尝试使用jsp:UseBean失败,因为它不允许我将其声明为ArrayList或ArrayList字符串 尝试使用JSTL和EL不起作用,因为呈现程序完全忽略我的${articleList} 我显然做错了什么,但我不知道是什么。我是否错误配置了JSTL和EL?我是不是

我试图让我的JSP页面干净地遍历数据对象的ArrayList,并将每个数据对象的内容插入到一段HTML中。即使是一个简单的页面,它也无法正常工作。我将ArrayList作为属性放入HttpServletRequest对象中,但是:

尝试使用jsp:UseBean失败,因为它不允许我将其声明为ArrayList或ArrayList字符串

尝试使用JSTL和EL不起作用,因为呈现程序完全忽略我的${articleList}

我显然做错了什么,但我不知道是什么。我是否错误配置了JSTL和EL?我是不是在用一种过于复杂的方式去做一件更容易通过另一种方式实现的事情

我的控制器:

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>

首先,您的if条件是否实际执行。其次,getArticles实际上返回数据。实际的.jsp本身看起来不错;我从index.jsp从索引页面返回HTML。我知道EL不起作用,因为我已经测试过将字符串作为请求属性传递,但它也没有出现。这里有很多关于EL不起作用的讨论。例如