Javatpoint Logo
Javatpoint Logo

Struts 2 Iterator Tag example

1) Create index.jsp for input

This jsp page creates a form using struts UI tags. It receives name, password and email id from the user.

<a href="fetch">findPartner</a>

2) Create the action class

This action class inherits the ActionSupport class and overrides the execute method.
package mypack;
import java.util.ArrayList;
public class Find {
private ArrayList list=new ArrayList();
public ArrayList getList() {
	return list;
public void setList(ArrayList list) {
	this.list = list;

public String execute(){
	User u1=new User();
	u1.setEmail("[email protected]");
	User u2=new User();
	u2.setEmail("[email protected]");
	return "success";

3) Create the model
package mypack;
public class User {
private String userName,userPass,email;
public String getUserName() {
	return userName;
public void setUserName(String userName) {
	this.userName = userName;
public String getUserPass() {
	return userPass;
public void setUserPass(String userPass) {
	this.userPass = userPass;
public String getEmail() {
	return email;
public void setEmail(String email) { = email;

4) Create struts.xml

This xml file defines an extra result by the name input, and an interceptor jsonValidatorWorkflowStack.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" 
<package name="arr" extends="struts-default">
<action name="fetch" class="mypack.Find" method="execute">
<result name="success">welcome.jsp</result>

5) Create view component

It is the simple jsp file displaying the information of the user.

<%@ taglib uri="/struts-tags" prefix="s" %>
Data is:<br/>
<s:iterator value="list">
<table width="40%">
<tr><td><s:property value="userName"/></td></tr>
<tr><td><s:property value="userPass"/></td></tr>
<tr><td><s:property value="email"/></td></tr>

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA