Meaningless Drivel is fun!
The moose likes Struts and the fly likes Pagination Using Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pagination Using Struts" Watch "Pagination Using Struts" New topic

Pagination Using Struts

satheesh krishnaswamy
Ranch Hand

Joined: Mar 17, 2004
Posts: 137
Hi All,

Can anyone help me as how to implement pagination using Struts.
I should not use any third party taglibs.I can only use Apache.

Please help me as it is pretty urgent.

Thanks in advance
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
As far as I know, there's no built-in function within Struts that handles pagination, but it wouldn't be that hard to create your own pagination bean. Here are some suggestions:

  • The bean should have properties for: total number of rows, rows per page, current page, total number of pages, and a collection containing all the rows.
  • When the page is first displayed, read all the rows and populate the appropriate bean properties and store the bean in the HTTP Session.
  • When The user requests next page, previous page, etc., have the bean calculate which data to display.

  • Merrill
    Consultant, Sima Solutions
    Wes Sorensen

    Joined: Dec 02, 2005
    Posts: 13
    Merrill's is a pretty good solution that will eliminate multiple database calls and would work well for a small site or a small rowset, but the scaling of it might be a factor.

    Say you're doing this for eBay and someone does a search for "computer". This returns say 15,000 rows. This could be a serious memory and performance problem - atleast on the first request where it loads the bean.

    I like the bean idea with the different fields, but I'd say take out the collection of rows, create a separate bean of the rows for that page - whatever the number of rows to display on the page is. So each request for the next page would result in a database query to load the bean, but it should be a small hit. This way, you don't max out your server memory after the 100 person does a query.

    The advantages to Merrill's solution is that you can do a single database lookup, store the results and basically just refresh the page. If you're not concerned with the memory or you know certain pages will have a small rowset, you can use that solution. Otherwise, consider something that will scale well no matter how many rows get returned.
    Mohd. Yakub

    Joined: Nov 25, 2005
    Posts: 18
    Hi all,

    we can use struts-layout taglib ,to create much versatile interfaces including paging through pager tag.
    some more ,plz visit
    Paul Lester
    Ranch Hand

    Joined: Dec 27, 2002
    Posts: 40
    You might also want to look at JDBC 2.0's RowSet:
    I think that this would get you want you want in a very lightweight manner; however, you'd have to make sure that your DB vendor supports this extension. I know that Oracle supports.



    Where Photography meets vision.<br /><a href="" target="_blank" rel="nofollow"></a><br />Please stop by!<br /> <br />SCJP,SCWCD,SCJD,SCEA
    michelle Wang
    Ranch Hand

    Joined: Jan 12, 2004
    Posts: 65
    I use this tag lib, quite easy to implement:

    michelle Wang <br />SCJP 1.4
    jakes vandenberg

    Joined: Nov 05, 2004
    Posts: 14
    Originally posted by michelle Wang:
    I use this tag lib, quite easy to implement:

    Hi Michelle
    how do I specify my bean that I previously used in an iterate tag?
    do you have an example jsp to share?

    Naseem Khan
    Ranch Hand

    Joined: Apr 25, 2005
    Posts: 809
    Well What I think is pagination should be done at database level not at the presentation tier. Why you are having that much data in memory which you don't want to show on the first page.

    Suppose you have 3000 rows in database. With just say 100 different threads accessing you application, there will be 3000*100 no. of rows which you will have in memory in form of java objects.

    This link might help ...

    [Pagination problem]


    [ July 13, 2006: Message edited by: Naseem Khan ]

    Asking Smart Questions FAQ - How To Put Your Code In Code Tags
    Jiya Khan

    Joined: Jul 07, 2009
    Posts: 3


    I have ArrayList of valueobject Things and need to display the details things name things price etc.. in some table structure..

    can any one guide me how to achieve pagiantion for ArrayList?
    code is as follows
    <% List defaultlist= new ArrayList();
    if(request.getAttribute("DefaultThings")!= null) {
    defaultlist = (List)request.getAttribute("DefaultThings");

    ListIterator iter1 = defaultlist.listIterator();
    String name= new String();
    int coun1t=0;
    while (iter1.hasNext()) {
    Things th1= (Things);
    name= th1.getThingsName();


    Ankit Garg

    Joined: Aug 03, 2008
    Posts: 9465

    Jiya please Dont Wake The Zombies, this thread is 3 years old, start a new topic for your question by clicking on ...

    SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
    I agree. Here's the link:
    subject: Pagination Using Struts
    It's not a secret anymore!