简体   繁体   English

JSTL:对于每个循环遍历集合

[英]JSTL: for Each loop to iterate over collection

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. 以下是我的代码段,在我从Spring 2迁移到Spring 3以及从Jstl 1.1迁移到jstl 1.2之前一直运行良好。 Now, its not working and keep on giving the error fEvents cannot found on object location 现在,它无法正常工作,并继续给出错误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上显示它们。任何建议都值得赞赏!!!

It looks like the object called "location" does not have an fEvents property. 看起来名为“ location”的对象没有fEvents属性。 Is it actually called ftpEvents? 它实际上叫做ftpEvents吗? Do you need to just change the variable name? 您是否只需要更改变量名?

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。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM