Solved

need tutorial to display 15 records per page

Posted on 2006-07-13
2
277 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

12 Experts available now in Live!

Get 1:1 Help Now