这是我拥有的数组的一个例子:
String[] dataName = {"Gene Name","Promoter Name","Source","Year","Author"};
String[] proteinList = {"protein01","AOX","Yarrowia","2006","John Doe","protein02","pGAP","Homo sapiens","1997","John Smith"};
实际数组最多可包含30个值。
数据的显示应该在这样的表中:
| Gene Name | Promoter Name | Source | Year | Author |
| protein01 | AOX | Yarrowia | 2006 | John Doe |
| protein02 | pGAP | Homo sapiens | 1997 | John Smith|
但我得到的结果是:
| Gene Name | Promoter Name | Source | Year | Author |
| protein01 | AOX | Yarrowia | 2006 | John Doe | protein02 | pGAP | Homo sapiens | 1997 | John Smith|
在JSTL中,这就是我写的:
<tr>
<c:forEach items="${dataName}" var="namedata">
<td class="body" valign="top" align="left"><b><c:out value="${namedata}"/></b></td>
</c:forEach>
</tr>
<tr>
<c:forEach items="${proteinList}" var="result">
<td class="datafield" valign="top"><c:out value="${result}"/></td>
</c:forEach>
</tr>
我有什么方法可以使用循环,以便proteinList[]
在新行中循环到proteinList[5]
?
非常感谢你的帮助。
答案 0 :(得分:0)
尝试这样,当索引到达第5个元素时插入tr标记:
<tr>
<c:forEach items="${dataName}" var="namedata">
<td class="body" valign="top" align="left"><b><c:out value="${namedata}"/></b></td>
</c:forEach>
</tr>
<c:forEach items="${proteinList}" var="result" varStatus="proteinCount">
<c:if test=((proteinCount.count+1)/5)=0>
<tr>
</c:if>
<td class="datafield" valign="top"><c:out value="${result}"/></td>
<c:if test=((proteinCount.count+1)/5)=0>
</tr>
</c:if>
</c:forEach>