以前没有将循环用到表格上,在写之前觉得蛮简单,结果自己写的吧,一直有bug,然后找了度娘,下面是成品代码。
运行效果如图
[img]http://dl2.iteye.com/upload/attachment/0104/5844/ecf46487-bdc7-3a34-8d1d-50e8125ca87c.png[/img]
其中关键的代码是
其中mod是取余的。5代表你想要多少个td,即一行你想要多少列,取余的值不能是0,是0会出现第一行会比预期少一行,后面的正常,取余的值为1,则都正常。
<body class="c-body">
<h1 class="bar" align="left">${name }-详细信息</h1>
<c:forEach var="en" items="${enMap }">
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="15" cellspacing="1" bgcolor="#E3E3E3" class="lanf16">
<tr>
<td align="center" bgcolor="#F5F5F5">${en.key }(${fn:length(en.value)})</td>
</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#E3E3E3" class="f12">
<tr>
<c:forEach items="${en.value }" var="env" varStatus="status">
<c:if test="${(status.count) mod 5 != 1}">
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
<c:if test="${(status.count) mod 5==1}">
<tr>
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
</c:forEach>
</tr>
</table>
</c:forEach>
</body>
运行效果如图
[img]http://dl2.iteye.com/upload/attachment/0104/5844/ecf46487-bdc7-3a34-8d1d-50e8125ca87c.png[/img]
其中关键的代码是
<c:forEach items="${en.value }" var="env" varStatus="status">
<c:if test="${(status.count) mod 5 != 1}">
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
<c:if test="${(status.count) mod 5==1}">
<tr>
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
</c:forEach>
其中mod是取余的。5代表你想要多少个td,即一行你想要多少列,取余的值不能是0,是0会出现第一行会比预期少一行,后面的正常,取余的值为1,则都正常。