您好,欢迎来到易妖游戏网。
搜索
您的当前位置:首页Struts2 控制 标签 之 Iterator Tag

Struts2 控制 标签 之 Iterator Tag

来源:易妖游戏网

Iterator Tag

 

In this section, we are going to describe the Iterator tag. Iterator tag is used to iterate over a value. An iterable value can be either of: java.util.Collection, java.util.Iterator.

Add the following code snippet into the struts.xml file.

struts.xml

<action name="iteratorTag" class="net.roseindia.iteratorTag">
  <result>/pages/genericTags/iteratorTag.jsp</result>
</action>

Create an action class  as shown:  

iteratorTag.java

package net.roseindia;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;

public class iteratorTag extends ActionSupport{
  
  private List myList;
  
  public String execute()throws Exception{
  myList = new ArrayList();
  myList.add("Fruits");
  myList.add("Apple");
  myList.add("Mango");
  myList.add("Orange");
  myList.add("Pine Apple");
  return SUCCESS;
  }

  public List getMyList(){
  return myList;
  }
}

 

The following example retrieves the value of the getMyList() method of the current object on the value stack and uses it to iterate over. The <s:property/> tag prints out the current value of the iterator.

iteratorTag.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
 
<head>
 
<title>Iterator Tag Example!</title>
 
</head>
 
<body>
 
<h1><span style="background-color: #FFFFcc">Iterator Tag Example!</span></h1>
 
<s:iterator value="myList">
 
<s:property /><br>
 
</s:iterator>
 
</body>
</html>

 Output of An Iterator Tag Example

 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- vipyiyao.com 版权所有 湘ICP备2023022495号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务