如何在JSTL中显示多维数组?

时间:2012-02-12 20:32:56

标签: jsp jstl

我有这个班级

public class Step {
    public int x;
    public int y;
    public int id;
}

我的servlet创建一个二维数组,如下所示:

Step[][] steps = new Step[size][size];

部分步骤为null,部分步骤不是null。然后它按如下方式转发到JSP:

request.setAttribute("gamesSteps", steps);          
request.getRequestDispatcher("/game.jsp").forward(request, response);

在JSP中,我按如下方式显示它们:

< c:forEach items="${requestScope.gamesSteps}" var="steps"> 
    < c:forEach items="${steps}" var="step">                   
        < c:out value="${step.id} "/>       
    < /c:foreach>     
< /c:forEach>

但没有出现。这是怎么造成的,我该如何解决?

2 个答案:

答案 0 :(得分:0)

您的属性需要getter方法。

添加

public int getId() {
 return id;
}

到你的班级。

您必须遵守JavaBeans规范。

答案 1 :(得分:0)

您有一些输入错误。试试这种方式。

<c:forEach items="${requestScope.gamesSteps}" var="steps"> 
<c:forEach items="${steps}" var="step">                   
    <c:out value="${step.id} "/>       
</c:forEach>     
</c:forEach>
相关问题