Struts 2 Append Tag Example

On this page, you will learn how to concatenate the multiple lists into a single list. To do this type of operation Struts 2 provide the append tag to perform the operation.

Similar Post: Struts 2 Merge Tag Example

In my example, I have appended the three ArrayList into a single list, two HashMap into a single map and two ArrayList with two HashMap. And by using iterator we will iterate all the values.

Note: Struts 2 append tag always concatenate the value next to the first.

Action Class

Create an action class with three ArrayList and two HashMap. Add the values in all.
package org.websparrow;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;

public class AppendTagAction extends ActionSupport {

	private static final long serialVersionUID = -2422285858809271233L;
    // Generate getters and setters...
	private List<String> list1 = new ArrayList<>();
	private List<String> list2 = new ArrayList<>();
	private List<Integer> list3 = new ArrayList<>();

	private Map<String, String> map1 = new HashMap<>();
	private Map<Integer, String> map2 = new HashMap<>();

	public String execute() throws Exception {

		// ArrayList Data

		// HashMap Data
		map1.put("New Delhi", "India");
		map1.put("Washington DC", "USA");
		map1.put("Moscow", "Russia");
		map2.put(1, "One");
		map2.put(2, "Two");
		map2.put(3, "Three");

		return SUCCESS;

JSP Page

On the JSP page use the struts2 append tag to combine 3 ArrayList, 2 HashMap and 2 ArrayList + 2 HashMap into a single iterator.

<%@taglib prefix="s" uri="/struts-tags"%>
	<h1>Struts 2 Append Tag Example</h1>
	<h3>ArrayList Append Example</h3>
	<s:append var="myArrayList">
		<s:param value="%{list1}"></s:param>
		<s:param value="%{list2}"></s:param>
		<s:param value="%{list3}"></s:param>
		<s:iterator value="%{#myArrayList}">
			<li><s:property /></li>

	<h3>HashMap Append Example</h3>
	<s:append var="myHashMap">
		<s:param value="%{map1}"></s:param>
		<s:param value="%{map2}"></s:param>
		<s:iterator value="%{#myHashMap}">
			<li><s:property /></li>

	<h3>ArrayList and HashMap Append Example</h3>
	<s:append var="myArrayListHashMap">
		<s:param value="%{map1}"></s:param>
		<s:param value="%{map2}"></s:param>
		<s:param value="%{list1}"></s:param>
		<s:param value="%{list2}"></s:param>
		<s:iterator value="%{#myArrayListHashMap}">
			<li><s:property /></li>


Map the action class in struts.xml.

<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
	<constant name="struts.devMode" value="true" />
	<package name="default" namespace="/" extends="struts-default">
		<action name="details" class="org.websparrow.AppendTagAction">
			<result name="success">/index.jsp</result>

To see the changes, deploy the application into the Tomcat » webapps folder and hit the below URL on your browser. You will find the output as shown in the figure.

URL: localhost:8090/Struts2AppendTag/details

Struts 2 Append Tag Example

Download Source Code:


  1. Control Tags

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.