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>
</body>
</html>
Output of the Append Tag Example:

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

被折叠的 条评论
为什么被折叠?



