關於Struts的logic:iterator標籤

wozuibt發表於2005-07-06
請看下面程式碼:

<%
  float collectHour=0;
  Collection outputs=(Collection)request.getAttribute("outputs");
  Iterator itOps=outputs.iterator();
  while(itOps.hasNext()){
    OutputInfo oi=(OutputInfo)itOps.next();
    out.println("<tr>");
    out.println("<td class='td_font'>"+oi.getEmpName()+"</td>");
    out.println("<td class='td_font'>"+oi.getPartID()+"</td>");
    out.println("<td class='td_font'>"+oi.getPartName()+"</td>");
    out.println("<td class='td_font'>"+oi.getWorkID()+"</td>");
    out.println("<td class='td_font'>"+oi.getListID()+"</td>");
    out.println("<td class='td_font'>"+oi.getUnit()+"</td>");
    out.println("<td class='td_font'>"+oi.getPiece()+"</td>");
    out.println("<td class='td_font'>"+oi.getManHour()+"</td>");
    out.println("</tr>");

<font color='ff0000'>collectHour+=oi.getManHour();</font>
  }
%>
<p class="indent">

轉換成Struts:
<%
  float collectHour=0;
%>
<logic:iterate id="ops" name="outputs" scope="request">
<tr>
<td class="td_font"><bean:write name="ops" property="empName"/></td>
<td class="td_font"><bean:write name="ops" property="partID"/></td>
<td class="td_font"><bean:write name="ops" property="partName"/></td>
<td class="td_font"><bean:write name="ops" property="workID"/></td>
<td class="td_font"><bean:write name="ops" property="listID"/></td>
<td class="td_font"><bean:write name="ops" property="unit"/></td>
<td class="td_font"><bean:write name="ops" property="piece"/></td>
<td class="td_font"><bean:write name="ops" property="manHour"/></td>
</tr>
</logic:iterate>
<p class="indent">


我希望logic每迴圈一次,collectHour都加上manHour的值,也就是說第一段程式碼的紅色字型部分應該怎麼轉換成Struts,請大家指點?

相關文章