Solved

need tutorial to display 15 records per page

Posted on 2006-07-13
2
275 Views
Last Modified: 2010-04-01
Hi I was trying to put 15 records of data in one page and needed a navigation system to go back and forth

would anyone know of any tutorial which explains this step by step. I am using plain servlet code and not jstl or tag library.

I would really appreciate your help

thanks

0
Comment
Question by:huzefaq
2 Comments
 
LVL 8

Accepted Solution

by:
kaliyugkaarjun earned 300 total points
ID: 17105922
0
 
LVL 3

Assisted Solution

by:anumalas
anumalas earned 200 total points
ID: 17106224
Hi

the bellow code will help you

<%@ page import="java.util.*, java.sql.*, sun.jdbc.rowset.*" %>

<html>
<head>
<title>[insert your title here]</title>
</head>

<body bgcolor="#ffffee" text="blue">
<form target="_top" name=viewForm action="pagination_test.jsp" method="post">
<%! int numPages = 0; %>
<%
String columnName = "";
int count = 0;
int totalCols = 0;
int increment = 1;
int numRows = 0;

String startIndexString = request.getParameter("startIndex");

if(startIndexString == null) {
startIndexString = "1";
}

int startIndex = Integer.parseInt(startIndexString);

try{

totalCols = 1;
%>
<table border=1 align=center width="100%">
<tr>
<%
for(int j=1; j<=totalCols; j++) {
columnName = "testing "; //(String) resultSetMetaData.getColumnName(j);
%><td>
<b><% out.print(columnName+j); %></b>
</td>
<%}%>
</tr>
<%



List list = new ArrayList();


for( int i=0; i<20; i++){

list.add("item"+i);

}


numRows = list.size();

out.println(" total no. of records : "+ numRows );

int numRecordsPerPage = 7;

out.println(" Num of Records per page : " + numRecordsPerPage + "\n" );


numPages = numRows /numRecordsPerPage;

int remain = numRows % numRecordsPerPage;


if(remain != 0){

numPages = numPages +1;

}

out.println(" \n no. of pages : " + numPages );

if((startIndex + numRecordsPerPage) <= numRows) {

increment = startIndex + numRecordsPerPage;
}
else{

if (remain == 0){

increment = startIndex + numRecordsPerPage;

}else{

increment = startIndex + remain;
}
}


for(count = startIndex; count < increment; count++) {


%><tr><%
for(int i=1; i<=totalCols; i++) {

%><td><% out.println(list.get(count-1)); %></td><%
}
%></tr><%

}
%>
</table>
<br>
<br>
<%

%>
<table width = "100%">
<tr>
Displaying Records:
<% if(startIndex + numRecordsPerPage < numRows){%>
<%= " " + startIndex %> - <%= increment - 1 %>
<%}else{%>
<%= " " + startIndex %> - <%= numRows %>
<%}%>

<%if(startIndex != 1) {%>
<a href="pagination_test.jsp?startIndex=<%=startIndex-numRecordsPerPage%>">Previous</a>
<%}%>

<%increment += numRecordsPerPage;%>
<%if(startIndex + numRecordsPerPage <= numRows){%>
<a href="pagination_test.jsp?startIndex=<%=startIndex+numRecordsPerPage %>">Next</a>
<%}%>
</tr>
</table>
<%
}catch(Exception exc){
out.println(exc.toString());
} // end try-catch
%>

</form>
</body>
</html>
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A safe way to clean winsxs folder from your windows server 2008 R2 editions
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the fileā€¦
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now