iterator 的遍历 循环输出数字,页码

来源:互联网 发布:入我相思门 知我相思苦 编辑:程序博客网 时间:2024/04/29 20:51

.在action里加上totalpage属性,GET SET方法
2.第一种写法(推荐)
<s:iterator value="new int[totalpage]" status="i">
<s:property value="#i.index+1"/>
</s:iterator>

 

第二种写法,较第一种慢
<s:bean name="org.apache.struts2.util.Counter" id="i">
<s:param name="first" value="1"/> <s:param name="last" value="maxNum"/>
<s:iterator>
<s:property value="#i.current - 1"/>
</s:iterator>
</s:bean>
3.struts2.0和2.1上在iterator这个标签上有区别
如果是2.1把id改成var就可以了

在实际情况中可能不仅需要遍历出页码,还可能需要返回所选择的当前页,就第一种方法给出实例

 

 

到:第<select name="currentPage">
        <s:iterator value="new int[totalPage]" status="st">
         <s:if test='currentPage==#st.index+1'>
          <option value='<s:property value="#st.index+1"/>'
           selected="selected">
           <s:property value="#st.index+1" />
          </option>
         </s:if>
         <s:else>
          <option value='<s:property value="#st.index+1" />'>
           <s:property value="#st.index+1" />
          </option>
         </s:else>
        </s:iterator>

      </select>页