如何在 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>
但什么也没有显示。这是如何引起的以及如何解决?
I have this class
public class Step {
public int x;
public int y;
public int id;
}
My servlet creates a two dimensional array of it as follows:
Step[][] steps = new Step[size][size];
Some of steps are null
, some of steps are not null
. Then it forwards to JSP as follows:
request.setAttribute("gamesSteps", steps);
request.getRequestDispatcher("/game.jsp").forward(request, response);
In JSP, I'm displaying them as follows:
< c:forEach items="${requestScope.gamesSteps}" var="steps">
< c:forEach items="${steps}" var="step">
< c:out value="${step.id} "/>
< /c:foreach>
< /c:forEach>
But nothing shows up. How is this caused and how can I solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的属性需要 getter 方法。
添加
到您的班级。
您必须遵守 JavaBeans 规范。
You need getter methods for your attributes.
add
to your class.
You have to obey the the JavaBeans specification.
您有一些打字错误。试试这个方法。
You have some typing errors. Try it this way.