Iterator tag example of struts2.2.1
Posted on: December 31, 2010 at 12:00 AM
In this tutorial, you will see the use of iterator tag in struts 2.2.1 framework in java.

Iterator tag example of struts2.2.1

In this tutorial, we will introduce you to about 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. We use the iterator tag to iterator over the collection of Integers. Here the integer property is of type ArrayList.

Directory structure of iterator tag example.

Description of login validation example:

 1- index.jsp  ADS_TO_REPLACE_1

<title>Iterator tag example</title>
<a href="iterator.action"> Iterate ArrayList Element</a>
It display a user interface for login user. Which takes the user input.

package roseindia;

import java.util.ArrayList;

import com.opensymphony.xwork2.ActionSupport;

public class IteratorTagAction extends ActionSupport {
ArrayList<Integer>   obList=new ArrayList<Integer>();
  public String execute() throws Exception {
    return SUCCESS;
  public ArrayList getObList() {
    return obList;


It is a XML file. Here, we will create action mapping of action class.

<?xml version="1.0" encoding="UTF-8"?>
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 <constant name="struts.enable.DynamicMethodInvocation" value="false" />
   <constant name="struts.devMode" value="false" />
   <package name="sample" extends="struts-default">
     <action name="iterator" class="roseindia.IteratorTagAction">
       <result name="success">/jsp/iterator.jsp</result>

If execute method of LoginValidation class returns success then it will display, otherwise error.jsp page will be display. It also also displayed username and password of login user.



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

<title>Value of iterator </title>



<h2>Iterator tag of Struts2.2.1</h2>

Elements of ArrayList Collection.....ADS_TO_REPLACE_4

<s:iterator value="obList">

<s:property />








Download Select Source Code

Related Tags for Iterator tag example of struts2.2.1:



Advertisement null