使用 JSTL 在 table 中打印一个数组
Print an array in a table using JSTL
这是我的数组示例:
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 个值。
数据的显示应该是这样的table:
| 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]
?
非常感谢您的帮助。
这样尝试,当索引到达第 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>
这是我的数组示例:
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 个值。
数据的显示应该是这样的table:
| 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]
?
非常感谢您的帮助。
这样尝试,当索引到达第 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>