java JSTL:for Each 循环遍历集合
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15012848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSTL: for Each loop to iterate over collection
提问by Jason McKim
following is my snippet, which was working good untill I migrated from spring 2 to spring 3 and Jstl 1.1 to jstl 1.2. Now, its not working and keep on giving the error
fEvents cannot found on object location
以下是我的片段,它一直运行良好,直到我从 spring 2 迁移到 spring 3,从 Jstl 1.1 迁移到 jstl 1.2。现在,它不起作用并继续给出错误
fEvents cannot found on object location
<c:forEach items="${location.fEvents}" var="item" varStatus="loop">
<tr><td><form:input path="fEvents[${loop.index}].hostName" size="30" maxlength="200"/></td>
<td><form:input path="fEvents[${loop.index}].directory" size="30" maxlength="200"/></td>
<td><form:input path="fEvents[${loop.index}].userName" size="20" maxlength="20"/></td>
<td><form:input path="fEvents[${loop.index}].password" size="20" maxlength="20"/></td>
</tr>
</c:forEach>
need to iterate the ftpEvents and show them on jsp Any suggestion is appreciated!!!
需要迭代 ftpEvents 并在 jsp 上显示它们任何建议表示赞赏!!!
回答by Jason McKim
It looks like the object called "location" does not have an fEvents property. Is it actually called ftpEvents? Do you need to just change the variable name?
看起来名为“location”的对象没有 fEvents 属性。它实际上被称为 ftpEvents 吗?你只需要改变变量名吗?
Even with that, though, you'll probably want to do something more like this:
尽管如此,您可能还想做更多类似这样的事情:
<c:forEach items="${location.ftpEvents}" var="item">
<tr><td><form:input path="item.hostName" size="30" maxlength="200"/></td>
<td><form:input path="item.directory" size="30" maxlength="200"/></td>
<td><form:input path="item.userName" size="20" maxlength="20"/></td>
<td><form:input path="item.password" size="20" maxlength="20"/></td>
</tr>
</c:forEach>
...you don't need to even use the loop.index at all, if I'm interpreting your code correctly.
...如果我正确解释您的代码,您甚至根本不需要使用 loop.index 。