【问题标题】:How to display a row number using Struts <logic:iterate>如何使用 Struts <logic:iterate> 显示行号
【发布时间】:2015-12-23 11:47:11
【问题描述】:

我有一个ArrayList,我正在使用 Struts 1 &lt;logic:iterate&gt; 来迭代和显示表中的记录。由于列表大小现在更大,我需要在第一列中显示行号。如何做到这一点?

尝试过的选项:1

 <% long count = 1;%>
 <logic:iterate id="iter" name="empForm" property="empList"  >
 <tr>  <td> <%= count++ %>  <td>  </tr>

工作但不应该使用scriptlet。

尝试过的选项:2

<logic:iterate id="iter" name="empForm" property="empList" indexId="index" >

 <tr>  <td> <bean:write name="index"/> <td>  </tr>

问题:工作索引从 0,1,2 开始,需要为 1,2,3

如何显示为 1,2,3 而不是 0,1,2?

【问题讨论】:

标签: jsp struts struts-1 struts-tags


【解决方案1】:

您正在使用logic:iterate,它被一个框架(Struts 1)明确记录为“不应再使用”,该框架本身已被弃用并正式放弃了几年。停止使用 Struts 1,真的。

同时,至少要学习JSP ELthe JSTL。它们存在超过 10 年:

<c:forEach var="employee" varStatus="loopStatus" values="${empForm.empList}">
  <tr>
    <td>${loopStatus.index + 1}<td>
    <td><c:out value="${employee.name}"/></td>
  </tr>
</c:forEach>

【讨论】:

    【解决方案2】:

    代替

    <bean:write name="index"/>
    

    你可以使用

    <c:out value="${index + 1}"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 2015-04-25
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 2012-04-28
      相关资源
      最近更新 更多