Struts2 控制 标签 之 append

本文介绍了一个使用Struts2框架中的AppendTag的例子。通过创建两个列表并利用<s:append>标签将它们合并为一个迭代器,展示了如何在一个JSP页面上遍历合并后的列表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

struts.xml

 

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

 

Create two lists in the action class and populate them with various items as shown in the  "AppendTag" class

 

AppendTag.java

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

public class AppendTag extends ActionSupport{
  
  private List myList;
  private List myList1;

  public String execute()throws Exception{
  myList = new ArrayList();
  myList.add("www.Roseindia.net");
  myList.add("Deepak Kumar");
  myList.add("Sushil Kumar");
  myList.add("Vinod Kumar");
  myList.add("Amit Kumar");

  myList1 = new ArrayList();
  myList1.add("www.javajazzup.com");
  myList1.add("Himanshu Raj");
  myList1.add("Mr. khan");
  myList1.add("John");
  myList1.add("Ravi Ranjan");
  return SUCCESS;
  }

  public List getMyList(){
  return myList;
  }

  public List getMyList1(){
  return myList1;
  }
}

 

 

Now create a jsp page using <s:append> and <s:iterator> tags as shown in the AppendTag.jsp page. The append tag is used to merge multiple iterators into one iterator. The "id" parameter keeps the resultant appended iterator stored under the stack's context and the "value" parameter is used to get the values contained within the resultant iterator.

 

 

AppendTag.jsp

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

<html>
 
<head>
 
<title> Append Tag Example!</title>
 
</head>
 
<body>
 
<h1><span style="background-color: #FFFFcc"> Append Tag Example!</span></h1>


 

< s : append id = "myAppendList" >


 

< s : param value = "%{myList}" />


 

< s : param value = "%{myList1}" />


 

</ s : append >


 

< s : iterator value = "%{#myAppendList}" >


 

< s : property />< br >


 

</ s : iterator >


 

</body>
</html>

 

Output of the  Append Tag Example: 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值