Struts2 Pagination Using Display Tags

Struts2 Pagination Using Display Tags

Posted in : Java Posted on : November 4, 2011 at 6:04 PM Comments : [ 0 ]

In this section, you will learn how to add pagination in your Struts2 application using Display tag.

Struts2 Pagination Using Display Tags

In this section, you will learn how to add pagination in your Struts2 application using Display tag.

Using Display tag, its become very easy to add pagination in your application. It is specially beneficial where you need to display a long list of data in a limited space without changing the page.

In this tutorial, the top ten list of richest sports person in world in the year 2009(according to Forbes magazine) is displayed using Struts2 with Display tag library 1.2.

The jar file used in the application is given below :

You can download the Display tag library 1.2 from here .

The hierarchy of the project is given below :



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns=""


<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"

<form-bean name="HomeForm"

<action input="/" name="HomeForm" path="/homeAction"
scope="session" type="com.devmanuals.struts2.HomeAction">
<forward name="success" path="/home.jsp" />

package com.devmanuals.struts2;

import java.util.ArrayList;

public class RichSportsmanList {

private int place;
private String name;
private int age;
private double annualIncome;
public RichSportsmanList(){


public RichSportsmanList(int place, String name, int age, double annualIncome) { = place; = name;
this.age = age;
this.annualIncome = annualIncome;

public ArrayList<RichSportsmanList> loadData() {
ArrayList<RichSportsmanList> sportsmanList = new ArrayList<RichSportsmanList>();
sportsmanList.add(new RichSportsmanList(1, "Tiger Woods", 35, 115));
sportsmanList.add(new RichSportsmanList(2, "David Beckham", 36, 50));
sportsmanList.add(new RichSportsmanList(3, "Michael Jordan", 48, 45));
sportsmanList.add(new RichSportsmanList(4, "Phil Mickelson", 41, 45));
sportsmanList.add(new RichSportsmanList(5, "Kimi Raikkonen", 32, 44));
sportsmanList.add(new RichSportsmanList(6, "Kobe Bryant", 33, 39));
sportsmanList.add(new RichSportsmanList(7, "LeBron James", 26, 38));
sportsmanList.add(new RichSportsmanList(8, "Ronaldinho", 31, 37));
sportsmanList.add(new RichSportsmanList(9, "Roger Federer", 35, 30));
sportsmanList.add(new RichSportsmanList(10,"Alex Rodriguez", 36, 34));
return sportsmanList;
public int getPlace() {
return place;
public void setPlace(int place) { = place;
public String getName() {
return name;
public void setName(String name) { = name;
public int getAge() {
return age;
public void setAge(int age) {
this.age = age;
public double getAnnualIncome() {
return annualIncome;
public void setAnnualIncome(double annualIncome) {
this.annualIncome = annualIncome;

package com.devmanuals.struts2;

import java.util.ArrayList;

public class HomeForm extends org.apache.struts.action.ActionForm {

private ArrayList<RichSportsmanList> richSportsmanList;

public ArrayList<RichSportsmanList> getRichSportsmanList() {
return richSportsmanList;

public void setRichSportsmanList(ArrayList<RichSportsmanList> richSportsmanList) {
this.richSportsmanList = richSportsmanList;

package com.devmanuals.struts2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class HomeAction extends Action {

private final static String SUCCESS = "success";

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HomeForm homeForm = (HomeForm) form;
RichSportsmanList sportsmanList = new RichSportsmanList();
return mapping.findForward(SUCCESS);



<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<jsp:forward page=""/>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<%@taglib uri="" prefix="display" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Forbes Top 10 Richest Sports Stars 2009</title>
<link href="css/displaytag.css" rel="stylesheet" type="text/css" />
<h2>Forbes Top 10 Richest Sports Stars 2009</h2>
<display:table export="true" id="data"
requestURI="/" pagesize="3">
<display:column property="place" title="Place" sortable="true"/>
<display:column property="name" title="Name" sortable="true"/>
<display:column property="age" title="Age" sortable="true"/>
<display:column property="annualIncome" title="Income(in m/yr)"
sortable="true" />
<p>Note : List is according to Forbes List 2009</p>


After executing the project, you will get the following output :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics