This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Paging in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Paging in JSP" Watch "Paging in JSP" New topic

Paging in JSP

Rajeev Kashyap

Joined: Sep 07, 2004
Posts: 19
I have 50 values those are comimg from database , but I want only 10 values show at a time and a link next. If I click next, I should go to other next 10 values and so on. How can I achieve it. Pls get back to me soon since I am stuck with problem.

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
If you search this forum, you should find that this question is asked all the time. You can find your solution that way.

Arundhathi Menon
Ranch Hand

Joined: Jan 14, 2004
Posts: 113
U need to fisrt include the jar -pager-taglib.jar in the lib of the WEB-INF folder

Try modifying this piece of code

<%@ taglib uri="" prefix="pg" %>

<pg ager
items="<%=DataSize %>"
index="<%= index %>"
maxPageItems="<%= maxPageItems %>"
maxIndexPages="<%= maxIndexPages %>"
isOffset="<%= true %>"

<pg aram name="style"/>
<pg aram name="position"/>
<pg aram name="index"/>
<pg aram name="maxPageItems"/>
<pg aram name="maxIndexPages"/>

int pagemove=0;
if (offset.intValue()>DataSize){
pagemove= offset.intValue();


<% if ("top".equals(position) || "both".equals(position)) { %>
int currpg=pagemove+15;
<font class = "firstlevel" size="2" > DISPLAYING RECORDS  <%=pagemove%>-<%=currpg%>/<%=DataSize%>    


<a href="/tas/<%=0%>"><nobr>[ First ] </nobr></a>

<pg rev>
<a href="/tas/<%=pagemove-15%>"><nobr>[ Prev ] </nobr></a>
</pg rev>


<a href="/tas/<%=pagemove +15%>"><nobr>[ Next ]  </nobr></a>

<a href="/tas/<%=DataSize-15%> "><nobr>[ Last ] </nobr></a></font>


<% } %>


int a = 0;
<TD colspan="10"><font class = "generalfont">  No records to Display</font></TD>
for (int i = pagemove,
l = Math.min(i + maxPageItems, DataSize);
i < l; i++)


<% System.out.println(((java.util.Properties)(TimeSheet.toArray()[i])).getProperty("status"));
if(((java.util.Properties)(TimeSheet.toArray()[i])).getProperty("status").equals("APPROVED")) { %>
<td><input name="timeid" type="checkbox" disabled="true" value=<%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("timeId")%>></td>
<%} else {%>
<td><input name="timeid" type="checkbox" value=<%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("timeId")%>></td>
<% }%>

<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("projName") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("taskName") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("activity") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("startTime") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("endTime") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("duration") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("status") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("date") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("Comment") %></font></TD>


</pg ager>

Hope this is of some help


With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Paging in JSP