0

我正在尝试用 JSTL 做一个标准的 foreach 循环,但似乎无法让它工作。数据存在,因为 jps 页面的其他部分工作。然而,这个 foreach 循环不会:

        <p> Script version
        <% // scrip version
            List test = (List)request.getAttribute("names");

            out.println(test.get(0).toString());
        %>
        </br>
        El version
        </br>
        ${names}
        </br>
    <c:forEach var="name" items="${names}">
        He is: ${name} </br>
    </c:forEach>
    </p>

我不确定为什么会这样?脚本版本有效,只需打印 ${names} 就可以查看列表。但是 foreach 不起作用。

names 是从我的控制器类发送的列表。

任何帮助都会很棒!干杯!

4

1 回答 1

0

Thanks go to Sotirios Delimanolis andJB Nizet for pointing me in the correct direction. I needed to include the JSLT library at the top of my JSP page. To do this, you need to include the library in your project, as well as declare it at the top using this line:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

For other tag libraries, you need to do the same.

Thanks guys for sending me in the right direction!

于 2013-11-03T18:38:30.790 回答