Next,Previous Page + Limit Records display????????

kennethcky used Ask the Experts™

How to use JSP to limit records display in a page? let say
10 or 15 records per page. And then show "Next"
or "Previous" Page navigation to show next 10 or 15

Can anyone show me an URL that teach how to code? or if
anyone know how to............

I would like to do it purely using JSP only without
JavaBean, is it possible or a good implementation?

Pls Advice

thanks a lot
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

use an offset and a counter when you are going through your resultset.

That should do it.

or check out:

you page should be able to take a parameter, for example "page", it looks like:


in you jsp page:
1. get user required page number:
int currentPage = Integer.parseInt(request.getParameter( "page" ));

2. create you next, previous link like:
<a href="mypage.jsp?page="<%=currentPage+1%>">Next</a>
<a href="mypage.jsp?page="<%=currentPage-1%>">Prev</a>

3. calculate the number of rows you need to skip in your resultset based on current page number and rows per page.

of cause you need to handly first page and last page to not disply "next" or "prev" link.
The question is for CJ. Can You give me an example that will work with tag from,
when the data is from jdbc. i don't know how to give the data.
If my data is very big, let say 60000 rows.Can i cache,or just to select one time and take 15rows,and then select again and take from 15throw. thanks
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

hi Raimis,
  Plz read this section:

  As you can see you need to pretty much either create a custom tag lib that iterates over your data or loop through your data and use <pg:Item> for each item displayed.

  What I would do is take your resultset and store it in an ArrayList and use that as your dataset.  You can attach it to the request (if the resultset is gotten in a servlet)

Does that make sense?

Its ok to store in an ArrayList, but if i have lets say 2000000 rows. And may ArrayList will be too big. Do you have an optimal solution for very large data?
Thanks a lot for helping!!!


ArrayList will be fine for that.. but you aren't displaying all 2000000 rows.. why not iterate over the resultset and only get what you need from it.

Can you give me an example about result set iteration, please!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial