struts2中的迭代标签的用法与例子

s:iterator 标签有3个属性:
    value:被迭代的集合
    id   :指定集合里面的元素的id
    status 迭代元素的索引

你可以用status(迭代元素的索引)来判断 #status.index == 3
2:索引的用法
如果指定了status,每次的迭代数据都有IteratorStatus的实例,它有以下几个方法
int getCount()返回当前迭代了几个元素
int getIndex()返回当前元素索引
boolean isEven()当然的索引是否偶数
boolean isFirst()当前是否第一个元素
boolean isLast()
boolean isOdd()当前元素索引是否奇数


   
        现在的索引是奇数为:
   

    当前元素值:

 
如果从你的Action中返回的是list,可采用如下方式:
     
           
      
           
        

       


 
 
 
 
 
 
 
 
 
 
 
 
 
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>


 
 
  My JSP 'index.jsp' starting page
 
 
 
 
 
 
 
 
  This is success JSP page.
 

 

  

  

   ${p.zhanghao}
  

  
  

 
  
   
              value="password" />
   

   
              value="password" />
   

   

  

 
 
 

  

  

  
    ${o.zhanghao} ${o.password}

  

 


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shanglovejava/archive/2010/02/12/5307684.aspx

你可能感兴趣的:(j2ee,struts,iterator,stylesheet,jsp,string,path)