Home Struts Struts Struts2.2.1 Tags Iterator tag example of struts2.2.1

Ask Questions?

View Latest Questions


 
 

Iterator tag example of struts2.2.1
Posted on: December 31, 2010 at 12:00 AM
Advertisement
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  

<html>
<head>
<title>Iterator tag example</title>
</head>
<body>
<a href="iterator.action"> Iterate ArrayList Element</a>
</body>
</html>

2-IteratorTagAction.java
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 {
    obList.add(1);
    obList.add(2);
    obList.add(3);
    obList.add(4);
    obList.add(5);    
    obList.add(6);    
    return SUCCESS;
  }
  public ArrayList getObList() {
    return obList;
  }
}

struts.xml

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

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">    
<struts>
 <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>
     </action>
   </package>
 </struts>
 

iterator.jsp
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.

<html>

<head>

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

<title>Value of iterator </title>

</head>

<body>

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

Elements of ArrayList Collection.....

<s:iterator value="obList">

<s:property />

<br />

</s:iterator>

</body>

</html>

index.jsp

iterator.jsp

Download Select Source Code


Related Tags for Iterator tag example of struts2.2.1:


DMCA.com