Solved

need tutorial to display 15 records per page

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web service Rest Client creation 4 85
java.util.concurrent.locks in java 3 191
best tutorial on log4j and logging for servlets/jsp codes 1 64
instanceof  operator in java 26 91
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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