如果您首先在Java中展开所有循环,然后在JSP中展开,那么您基本上是在执行这些命令(按此顺序),给定3个要显示的对象:
renderRequest.setAttribute("optionalDate", someDate);
renderRequest.setAttribute("optionalDate", someOtherDate);
renderRequest.setAttribute("optionalDate", yetSomeOtherDate);
renderRequest.getAttribute("optionalDate");
renderRequest.getAttribute("optionalDate");
renderRequest.getAttribute("optionalDate");
setAttribute
不是
pushToQueue
和
getAttribute
不是
nextFromQueue
(比喻地说),你只会
yetSomeOtherDate
当然,对于JSP循环的所有迭代。
你也可以
-
计算JSP中的值,
-
根据当前对象存储一个为您计算的对象,
-
使用对象的ID作为其键的一部分来存储属性,例如:。
"optionalDate-" + file.getId()
而不仅仅是泛型
"optionalDate"
. 然后在JSP中使用相同的键构造来读取适当的值。(我认为这很不雅观,但对于您的用例来说可能是务实的)