Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

paging of records using jsp 1

Status
Not open for further replies.

abyinsydney

Programmer
Feb 17, 2004
99
0
0
AU
greetings fellow citizens

Anyone have an example of how to implement paging of records using jsps.

i have 1000 records needs to display 20 records at a time with the previous and next functionality using jsp (no beans).Please help and thanx in advance


records have to displayed 20 records at a time
With an example is better to understand.

Thanks
aby
 
your records are being extracted from a database ?
 
venu
u r a genius and a legend you r code seems to work but the problem is how do i embed it in my code .below is my code could you please let me know how do i embed your code in to mine


below is my code .it is a very simple jsp just connecting to the datbase and retriving records

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<%@ page import=&quot;java.sql.*&quot; %>

<%
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=&quot; &quot;,r11=&quot; &quot;,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;


Connection con = null;
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
con = DriverManager.getConnection(&quot;jdbc:mysql://127.0.0.1:3306/archiving&quot;);
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = &quot;Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT &quot;+ currentRs +&quot;,10&quot;;
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);

while (rs.next())
{
r5 = rs.getString(&quot;account_no&quot;);
r6 = rs.getString(&quot;account_type&quot;);
r7 = rs.getString(&quot;prod_desig&quot;);
r8 = rs.getString(&quot;relationship_type&quot;);
r9 = rs.getString(&quot;primary_owning_cust&quot;);

%>



<!- TABLE FOR DETAILS STARTS HERE -->


<div id=&quot;Layer9&quot; style=&quot;position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;&quot;>
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id=&quot;Layer18&quot; style=&quot;position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;&quot;>
<table width=&quot;100%&quot; height=&quot;24&quot; border=&quot;0&quot;>
<tr>

</strong></td>
<td width=&quot;6%&quot;><div align=&quot;center&quot;> <strong>
<% out.println(&quot;&quot;+ r6);%>
</strong></div></td>
<td width=&quot;26%&quot;><div align=&quot;center&quot;><strong>
<% out.println(&quot;&quot;+ r7);%>
</strong></div></td>
<td width=&quot;21%&quot;><div align=&quot;center&quot;><strong>
<% out.println(&quot;&quot;+ r8);%>
</strong></div></td>
<td width=&quot;28%&quot;><div align=&quot;center&quot;><strong>
<% out.println(&quot;&quot;+ r9);%>
</strong></div></td>




</tr>

<% } %>
</table>


<strong>

</strong> </div>


</div>


</body>




</html>


your helping gesture is higly kept at high esteem
 
Hi,

It would be little difficult to integrate the 2 codes. To make the life simple write a java Object which holds the values from the resultSet and then add the Object to the ArrayList for every record from then you can use the other code to display the values in a set of 20 each...

Ex:

/**
*
* User: vreddy
* Date: Feb 18, 2004
* Time: 3:55:30 PM
*
*/
public class ResultRows {

private String r5;
private String r6;
private String r7;
private String r8;
private String r9;

public ResultRows() {
}

public ResultRows(String r5, String r6, String r7, String r8, String r9) {
this.r5 = r5;
this.r6 = r6;
this.r7 = r7;
this.r8 = r8;
this.r9 = r9;
}

public String getR5() {
return r5;
}

public void setR5(String r5) {
this.r5 = r5;
}

public String getR6() {
return r6;
}

public void setR6(String r6) {
this.r6 = r6;
}

public String getR7() {
return r7;
}

public void setR7(String r7) {
this.r7 = r7;
}

public String getR8() {
return r8;
}

public void setR8(String r8) {
this.r8 = r8;
}

public String getR9() {
return r9;
}

public void setR9(String r9) {
this.r9 = r9;
}
}

Compile this and copy the under WEB-INF/classes of your Webapplication.

Now Change your JSP page a little


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<%@ page import=&quot;java.sql.*, ResultRows&quot; %>

<%
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=&quot; &quot;,r11=&quot; &quot;,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

ArrayList list = null;
if(null != session.getAttribute(&quot;resultRows&quot;))
{
Connection con = null;
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
con = DriverManager.getConnection(&quot;jdbc:mysql://127.0.0.1:3306/archiving&quot;);
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = &quot;Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT &quot;+ currentRs +&quot;,10&quot;;
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
////
list = new ArrayList();
while (rs.next())
{
r5 = rs.getString(&quot;account_no&quot;);
r6 = rs.getString(&quot;account_type&quot;);
r7 = rs.getString(&quot;prod_desig&quot;);
r8 = rs.getString(&quot;relationship_type&quot;);
r9 = rs.getString(&quot;primary_owning_cust&quot;);
// //
list.add(new ResultRows(r5,r6,r7,r8,r9));
}
session.setAttribute(&quot;resultRows&quot;, list);
}else{

list = (ArrayList) session.getAttribute(&quot;resultRows&quot;);
}
%>

<!-- NOW YOU HAVE THE ARRAYLIST AND YOU CAN USE THE OTHER CODE FROM THE THREAD.-->

Hope this will help........

Cheers
Venu
 
greetings venu
Thanx a lot for yuor reply i tried embedding your code but it gives me an error
the following is the code i wrote for pagination in jsp

Below is the java class as suggested by you

public class ResultRows {

private String r5;
private String r6;
private String r7;
private String r8;
private String r9;

public ResultRows() {
}

public ResultRows(String r5, String r6, String r7, String r8, String r9) {
this.r5 = r5;
this.r6 = r6;
this.r7 = r7;
this.r8 = r8;
this.r9 = r9;
}

public String getR5() {
return r5;
}

public void setR5(String r5) {
this.r5 = r5;
}

public String getR6() {
return r6;
}

public void setR6(String r6) {
this.r6 = r6;
}

public String getR7() {
return r7;
}

public void setR7(String r7) {
this.r7 = r7;
}

public String getR8() {
return r8;
}

public void setR8(String r8) {
this.r8 = r8;
}

public String getR9() {
return r9;
}

public void setR9(String r9) {
this.r9 = r9;
}
}
i compiled it and kept it in the WEB-INF directory of my JRun server


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<%@ page import=&quot;java.sql.*, ResultRows&quot; %>

<%
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=&quot; &quot;,r11=&quot; &quot;,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

ArrayList list = null;
if(null != session.getAttribute(&quot;resultRows&quot;))
{
Connection con = null;
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
con = DriverManager.getConnection(&quot;jdbc:mysql://127.0.0.1:3306/archiving&quot;);
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = &quot;Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT &quot;+ currentRs +&quot;,10&quot;;
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
////
list = new ArrayList();
while (rs.next())
{
r5 = rs.getString(&quot;account_no&quot;);
r6 = rs.getString(&quot;account_type&quot;);
r7 = rs.getString(&quot;prod_desig&quot;);
r8 = rs.getString(&quot;relationship_type&quot;);
r9 = rs.getString(&quot;primary_owning_cust&quot;);
// //
list.add(new ResultRows(r5,r6,r7,r8,r9));
}
session.setAttribute(&quot;resultRows&quot;, list);
}else{

list = (ArrayList) session.getAttribute(&quot;resultRows&quot;);
}
%>
the above code was modifed by you it gives me an error.my code is mentioned below could you please have a look at my code it and send me a solution
your help is certainly praise worhty .let me know if i could be of any help to you here in australia

<body>
<%@ page import=&quot;java.sql.*&quot; %>

<%
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=&quot; &quot;,r11=&quot; &quot;,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;


Connection con = null;
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
con = DriverManager.getConnection(&quot;jdbc:mysql://127.0.0.1:3306/archiving&quot;);
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = &quot;Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT &quot;+ currentRs +&quot;,10&quot;;
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);

while (rs.next())
{
r5 = rs.getString(&quot;account_no&quot;);
r6 = rs.getString(&quot;account_type&quot;);
r7 = rs.getString(&quot;prod_desig&quot;);
r8 = rs.getString(&quot;relationship_type&quot;);
r9 = rs.getString(&quot;primary_owning_cust&quot;);

%>



<!- TABLE FOR DETAILS STARTS HERE -->


<div id=&quot;Layer9&quot; style=&quot;position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;&quot;>
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id=&quot;Layer18&quot; style=&quot;position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;&quot;>
<table width=&quot;100%&quot; height=&quot;24&quot; border=&quot;0&quot;>
<tr>

</strong></td>
<td width=&quot;6%&quot;><div align=&quot;center&quot;> <strong>
<% out.println(&quot;&quot;+ r6);%>
</strong></div></td>
<td width=&quot;26%&quot;><div align=&quot;center&quot;><strong>
<% out.println(&quot;&quot;+ r7);%>
</strong></div></td>
<td width=&quot;21%&quot;><div align=&quot;center&quot;><strong>
<% out.println(&quot;&quot;+ r8);%>
</strong></div></td>
<td width=&quot;28%&quot;><div align=&quot;center&quot;><strong>
<% out.println(&quot;&quot;+ r9);%>
</strong></div></td>




</tr>

<% } %>
</table>


<strong>

</strong> </div>


</div>


</body>




</html>

I think the suggestions yuo had suggested are valid just a minute erro of saying closing of bracket.

please help me out

thanx in advace
 
Hi,

Can you tell what is the error? If not give me your E-Mail I will post you the code.

Cheers,
Venu
 
Hi,

I am pasting the code below copy it and run the code. It will display records 2 at a time. Change the variable increment to 20 so that I will display 20 records at a time. Just make sure that u have the ResultRows.class in your webapplication/WEB-INF/classes. Form the below Comment the red lines and uncomment the blue lines. Hope this will hlep you get started with what you are looking for.

I haven't changed any code for the ResultRows.java, you can use the exisiting or copy the java file from the above.

<%@ page import=&quot;java.util.ArrayList,
java.util.Iterator,
java.util.List,
ResultRows,
java.sql.ResultSet,
java.sql.Statement,
java.sql.DriverManager,
java.sql.Connection&quot;%>
<%
ArrayList arrayList = null;
boolean check = true;
// session.removeAttribute(&quot;arrayList&quot;);
/* if you have the arrayList in the session Object avoid the DB Call
and get the ArrayList from the session Object
*/
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=&quot; &quot;,r11=&quot; &quot;,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

if(null == session.getAttribute(&quot;arrayList&quot;))
{
/** need to get the ArrayList from the DB */
arrayList = new ArrayList();

// START OF COMMIT LINE
for(int i=0; i<10; i++)
{
arrayList.add(new ResultRows(&quot;r5&quot;+i,&quot;r6&quot;+i,&quot;r7&quot;+i,&quot;r8&quot;+i,&quot;r9&quot;+i));
}
// END OF COMMIT LINE

//START OF UNCOMMIT LINE
/* Connection con = null;
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
con = DriverManager.getConnection(&quot;jdbc:mysql://127.0.0.1:3306/archiving&quot;);
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = &quot;Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT &quot;+ currentRs +&quot;,10&quot;;
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
while (rs.next())
{
r5 = rs.getString(&quot;account_no&quot;);
r6 = rs.getString(&quot;account_type&quot;);
r7 = rs.getString(&quot;prod_desig&quot;);
r8 = rs.getString(&quot;relationship_type&quot;);
r9 = rs.getString(&quot;primary_owning_cust&quot;);
// //
arrayList.add(new ResultRows(r5,r6,r7,r8,r9));
}
*/
// END OF UNCOMMIT LINE

session.setAttribute(&quot;arrayList&quot;, arrayList);
}else{
arrayList = (ArrayList)session.getAttribute(&quot;arrayList&quot;);
}

int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 2;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= &quot;Previous&quot;;
String next = &quot;Next&quot;;
List displayList = null;
if( null != request.getParameter(&quot;next&quot;))
{
fromIndex = Integer.parseInt(request.getParameter(&quot;next&quot;));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}

if( null != request.getParameter(&quot;prev&quot;))
{
toIndex = Integer.parseInt(request.getParameter(&quot;prev&quot;));
fromIndex = toIndex - increment;
}

if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0 )
previous = &quot;<a href=&quot;+ uri +&quot;?prev=&quot;+ fromIndex +&quot;> Previous </a>&quot;;
if(toIndex != 0 && check)
next = &quot;<a href=&quot;+ uri +&quot;?next=&quot;+ toIndex +&quot;> Next </a>&quot;;

/* out.println(arrayList);
out.println(&quot;<br>&quot;);
out.println(displayList);
out.println(&quot;<br>&quot;);
out.println(next);
out.println(&quot;<br>&quot;);
out.println(previous);*/

%>
<!- TABLE FOR DETAILS STARTS HERE -->

<div id=&quot;Layer9&quot; style=&quot;position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;&quot;>
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id=&quot;Layer18&quot; style=&quot;position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;&quot;>
<table width=&quot;100%&quot; height=&quot;24&quot; border=&quot;0&quot;>
<caption> <%=next%>             <%=previous%></caption>
<tr>
</strong>
</td>
<td width=&quot;6%&quot;><div align=&quot;center&quot;> <strong>
Account No
</strong></div>
</td>
<td width=&quot;26%&quot;><div align=&quot;center&quot;><strong>
Account Type
</strong></div>
</td>
<td width=&quot;21%&quot;><div align=&quot;center&quot;><strong>
Prod Design
</strong></div>
</td>
<td width=&quot;28%&quot;><div align=&quot;center&quot;><strong>
Relationship
</strong></div>
</td>
</tr>
<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
%>
<tr>
</strong>
</td>
<td width=&quot;6%&quot;><div align=&quot;center&quot;> <strong>
<%=resultRows.getR6()%>
</strong></div>
</td>
<td width=&quot;26%&quot;><div align=&quot;center&quot;><strong>
<%=resultRows.getR7()%>
</strong></div>
</td>
<td width=&quot;21%&quot;><div align=&quot;center&quot;><strong>
<%=resultRows.getR8()%>
</strong></div>
</td>
<td width=&quot;28%&quot;><div align=&quot;center&quot;><strong>
<%=resultRows.getR9()%>
</strong></div>
</td>
</tr>
<%}%>
</table>


<strong>

</strong> </div>


</div>

If any question or problems with the code you can let me know..

Cheers,
Venu
 
Greetings venu
I have kept the result row set in my web -inf directory and have uncommented and commented the line as instruted by you.


after following your procedures it does not pick up variables from the database but picks up variables from the arraylist .you get this result when you load the page



Next Previous
Account No Account Type Prod Design Relationship
r60 r70 r80 r90
r61 r71 r81 r91

on clicking the next i'm getting the result mentioned below

Next Previous
Account No Account Type Prod Design Relationship
r62 r72 r82 r92




below is my code please have a look at it
where are these variables coming from they are not coming from my database

Please help me you effort is really appreciative .
waiting anxiously for your reply

aby


<%@ page contentType=&quot;text/html; charset=iso-8859-1&quot; language=&quot;java&quot; import=&quot;java.sql.*&quot; errorPage=&quot;&quot; %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<%@ page import=&quot;java.util.ArrayList,
java.util.Iterator,
java.util.List,
ResultRows,
java.sql.ResultSet,
java.sql.Statement,
java.sql.DriverManager,
java.sql.Connection&quot;%>
<%
ArrayList arrayList = null;
boolean check = true;
// session.removeAttribute(&quot;arrayList&quot;);
/* if you have the arrayList in the session Object avoid the DB Call
and get the ArrayList from the session Object
*/
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=&quot; &quot;,r11=&quot; &quot;,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

if(null == session.getAttribute(&quot;arrayList&quot;))
{
/** need to get the ArrayList from the DB */
arrayList = new ArrayList();

/* // START OF COMMIT LINE
for(int i=0; i<10; i++)
{
arrayList.add(new ResultRows(&quot;r5&quot;+i,&quot;r6&quot;+i,&quot;r7&quot;+i,&quot;r8&quot;+i,&quot;r9&quot;+i));
} */
// END OF COMMIT LINE

//START OF UNCOMMIT LINE
Connection con = null;
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
con = DriverManager.getConnection(&quot;jdbc:mysql://127.0.0.1:3306/archiving&quot;);
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = &quot;Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT &quot;+ currentRs +&quot;,10&quot;;
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
while (rs.next())
{
r5 = rs.getString(&quot;account_no&quot;);
r6 = rs.getString(&quot;account_type&quot;);
r7 = rs.getString(&quot;prod_desig&quot;);
r8 = rs.getString(&quot;relationship_type&quot;);
r9 = rs.getString(&quot;primary_owning_cust&quot;);
// //
arrayList.add(new ResultRows(r5,r6,r7,r8,r9));
}

// END OF UNCOMMIT LINE

session.setAttribute(&quot;arrayList&quot;, arrayList);
}else{
arrayList = (ArrayList)session.getAttribute(&quot;arrayList&quot;);
}

int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 2;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= &quot;Previous&quot;;
String next = &quot;Next&quot;;
List displayList = null;
if( null != request.getParameter(&quot;next&quot;))
{
fromIndex = Integer.parseInt(request.getParameter(&quot;next&quot;));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}

if( null != request.getParameter(&quot;prev&quot;))
{
toIndex = Integer.parseInt(request.getParameter(&quot;prev&quot;));
fromIndex = toIndex - increment;
}

if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0 )
previous = &quot;<a href=&quot;+ uri +&quot;?prev=&quot;+ fromIndex +&quot;> Previous </a>&quot;;
if(toIndex != 0 && check)
next = &quot;<a href=&quot;+ uri +&quot;?next=&quot;+ toIndex +&quot;> Next </a>&quot;;

/* out.println(arrayList);
out.println(&quot;<br>&quot;);
out.println(displayList);
out.println(&quot;<br>&quot;);
out.println(next);
out.println(&quot;<br>&quot;);
out.println(previous);*/

%>
<!- TABLE FOR DETAILS STARTS HERE -->

<div id=&quot;Layer9&quot; style=&quot;position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;&quot;>
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id=&quot;Layer18&quot; style=&quot;position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;&quot;>
<table width=&quot;100%&quot; height=&quot;24&quot; border=&quot;0&quot;>
<caption> <%=next%> <%=previous%></caption>
<tr>
</strong>
</td>
<td width=&quot;6%&quot;><div align=&quot;center&quot;> <strong>
Account No
</strong></div>
</td>
<td width=&quot;26%&quot;><div align=&quot;center&quot;><strong>
Account Type
</strong></div>
</td>
<td width=&quot;21%&quot;><div align=&quot;center&quot;><strong>
Prod Design
</strong></div>
</td>
<td width=&quot;28%&quot;><div align=&quot;center&quot;><strong>
Relationship
</strong></div>
</td>
</tr>
<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
%>
<tr>
</strong>
</td>
<td width=&quot;6%&quot;><div align=&quot;center&quot;> <strong>
<%=resultRows.getR6()%>
</strong></div>
</td>
<td width=&quot;26%&quot;><div align=&quot;center&quot;><strong>
<%=resultRows.getR7()%>
</strong></div>
</td>
<td width=&quot;21%&quot;><div align=&quot;center&quot;><strong>
<%=resultRows.getR8()%>
</strong></div>
</td>
<td width=&quot;28%&quot;><div align=&quot;center&quot;><strong>
<%=resultRows.getR9()%>
</strong></div>
</td>
</tr>
<%}%>
</table>


<strong>

</strong> </div>


</div>

</body>
</html>
 
Hi,

Those are the values from previoius arrayList they are not from the DB. Coz the arrayList was stored in the session Object and it is getting that ArrayList. restart JRun and clear the server temp folder.

If not change the logic a little insted of checking the list in the session object let is check for next and prev request parameters.

if(null != request.getParameter(&quot;next&quot;) || null!= request.getParameter(&quot;prev&quot;))
{
// DB code
// sotre the list in session
}else{
// get the list from session
}

Cheers,
Venu
 
hi venu
your code worked however there is a hitch on one of the field account no .i need to make it a hyper link there are three values T,L S matching the account types clicking on these accounno should take me to 3 different pages.for instance

Account No Account Type Prod Design Relationship
r60 T r80 r90
r61 S r81 r91
ON CLICKING ON r6O SHOULD TAKE TO A DIFFERENT PAGE WITH ACCOUNT T PAGE PROPERTIES CLICKING ON r61 SHOULD TAKE ME TO ACCOUNT S PROPERTIES.THESE RECORDS ARE COMING FROM THE DATABASE AND ARE DISPLAYED 10 RECORDS AT A TIME.

If you could throw some lite i was able to get the progrmme working with all the records getting displayed however with no of records getting displaced on the page i'm having a problem how do one acheive it s goal

thanx in advance for your help
aby
 
Hi,

When clicked on the Account Type it should take to that particular page?

In the while loop of the iterator add a conditon.

<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
String hLink = "#";
if(resultRows.getR7().equals("T"))
hLink = "T.jsp";
else if (resultRows.getR7().equals("S"))
hLink = "S.jsp";
else if (resultRows.getR7().equals("L"))
hLink = "L.jsp";


%>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
<a href="<%=hLink%>"><%=resultRows.getR6()%></a>
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
<%=resultRows.getR7()%>
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
<%=resultRows.getR8()%>
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
<%=resultRows.getR9()%>
</strong></div>
</td>
</tr>
<%}%>
</table>


Cheers
Venu
 
Seems like a lot of work going on here, Did you read anything about using the paging tag lib for jsp? We needed to implement paging on our companies software and found a paging tag lib for jsp that only took 1 hour to implement for about 500 jsp pages. No backend work! It is only about 8 lines of code per jsp page! If you are still having issues, I would highly suggest looking into it.

A simple google search on paging tag lib, or JSP Paging will return useful sites like this one!

Lance
 
greetings mate
how do i implement jsp tags nothing is mentioned on the site i mean which code to write in the pages
 
If you install the jar for the tag lib there are jsp examples that have the paging implemented. Here is how I did it.

//Import the tag lib to the .jsp page.
<head>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
</head>

/* This line will be added above the records you want paged.
The indexSize is the amount of pages in the link menu for paging, and the pageSize is the number of items per page, I have it set to 15 page links, and 15 records per page. The url is the link to go to when the page link is clicked. built personal utility to grab the url and change the page number and send it send the appropriate page back. */
<pg:paging indexSize="15" pageSize="15" url="<%= Utilities.pagingRebuildURL(request) %>" >

/* This tag goes aroud each item, ours are built in a <c:foreach> loop which is imported through java core tag lib so we do not have to muck up our code with inline scripting!!!!! */
<pg:item>
~data to be displayed goes here~
</pg:item>

//Finaly at the bottom of the jsp, build the links for paging and close the paging tag.
<tr>
<th colspan="5" style="text-align: center;">
<pg:index>
<pg:page><%=thisPage%></pg:page>
</pg:index>
</th>
</tr>
</pg:paging>





// Here is the utility to return the url.
/**
* This function will rebuild a URL for paging index on listing pages.
*
* @param HttpServletRequest req
* @return void
*/
public static String pagingRebuildURL(HttpServletRequest req) throws IOException {

Enumeration reqparams = req.getParameterNames();
String url = req.getRequestURI();
boolean first = true;
String param_name = null;
while(reqparams.hasMoreElements()) {
param_name = (String)reqparams.nextElement();
if(param_name.equals("pageNum")) {
continue;
}
if(first) {
url += "?";
first = !first;
} else {
url += "&";
}
url += param_name + "=" + req.getParameter(param_name);
}
if(DEBUG)System.out.println(url);
return url;
}


This methodology works, you just need to read up some on the paging tag lib.

Hope this helps.
 
Greetings venu

Below is your code which i 'm trying to embed in my jsp page as suggested by you to display 20 records per page.


I have kept the result rows class in the web-inf directory.Howerver it does not display any record and gives me the following errror

Exception3: javax.servlet.ServletException: Exception thrown on line '362' from page 'C:\\JRun\\servers\\default\\archiving\\archiving\\jsp\\mem1.jsp'.<BR>

I have mentioned below the line seems like it is not picking up the class my code works perfectly fine with out pagination.

Could you please assist me in rectifying the problem.Please my project is due and my manger is eating my head out please help me

The sql are fine.SQL STATEMENTS ARE FINE .Please help

All sql are stored in result variable which is getting executed.Please help
aby



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0049) -->
<HTML><HEAD><TITLE>Untitled Document</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT language=JavaScript type=text/JavaScript>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</SCRIPT>

<META content="MSHTML 6.00.2800.1264" name=GENERATOR></HEAD>
<BODY>
<DIV id=Layer1
style="BORDER-RIGHT: #000000 1px; BORDER-TOP: #000000 1px; Z-INDEX: 1; LEFT: 0px; BORDER-LEFT: #000000 1px; WIDTH: 1050px; BORDER-BOTTOM: #000000 1px; POSITION: absolute; TOP: 0px; HEIGHT: 760px; BACKGROUND-COLOR: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000;"></DIV>
<div id="Layer2" style="position:absolute; left:13px; top:106px; width:970px; height:19px; z-index:1"><img src="/archiving/images/pixi_grey_blue.gif" width="976" height="21"></div>
<DIV id=Layer9
style="BORDER-RIGHT: #000000 1px; BORDER-TOP: #000000 1px; Z-INDEX: 42; LEFT: 15px; BORDER-LEFT: #000000 1px; WIDTH: 971px; BORDER-BOTTOM: #000000 1px; POSITION: absolute; TOP: 127px; HEIGHT: 404px; BACKGROUND-COLOR: #dfe9f9; layer-background-color: #DFE9F9">
<div id="Layer5" style="position:absolute; width:963px; height:25px; z-index:1; left: 6px; top: 4px;">
<div align="center"><strong><font color="#CC0033" size="5">
<!- TABLE FOR HEADER STARTS HERE -->
<!- ENTER JSP ENDS -->
<font color="#000066">Member Search Results</font></font></strong>
<div id="Layer8" style="position:absolute; width:953px; height:24px; z-index:43; left: 11px; top: 39px;">
<div align="left">
<table width="100%" border="0">
<tr>
<td width="11%"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#003366">C.I.F
No.</font></strong></font></div></td>
<td width="9%"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000066">Ins
I.D</font></strong>.</font></div></td>
<td width="17%"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Surname</strong></font></div></td>
<td width="27%"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Given
name</strong></font></div></td>
<td width="22%"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Address</strong></font></div></td>
<td width="14%"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>D.O.B</strong></font></div></td>
</tr>
</table>
</div>
</div>

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.ArrayList,
java.util.Iterator,
java.util.List,
ResultRows,
java.sql.ResultSet,
java.sql.Statement,
java.sql.DriverManager,
java.sql.Connection" %>
<%
String a1= request.getParameter("cifno");
String a2= request.getParameter("precifno");
String a3 = request.getParameter("accountno");
String a4 = request.getParameter("surname");
String a5 =request.getParameter("dob");
String a6 =request.getParameter("givenname");
String a7 = request.getParameter("tfn");
String a8 = request.getParameter("add");
String a9 = request.getParameter("postcode");
String a10 = request.getParameter("mailadd");
String a11 = request.getParameter("mailcode");
String a12 = request.getParameter("prename");
String a13= request.getParameter("chequefacility");
String a14= request.getParameter("cardno");
String a15= request.getParameter("overdraftsecurity ");
String a16= request.getParameter("overdraftvolume");
String a17= request.getParameter("loansecurity");
String a18= request.getParameter("loanvolume");
String a19= request.getParameter("select");
System.out.println("Value for select isa19 "+a19);
String a20= request.getParameter("select2");
String a21= request.getParameter("select3");

ArrayList arrayList = null;
boolean check = true;

if(null == session.getAttribute("arrayList"))
{

arrayList = new ArrayList();


Connection conn = null;


Class.forName("org.gjt.mm.mysql.Driver");
String url="jdbc:mysql://168.217.20.68/archiving";
conn = DriverManager.getConnection (url,"tasol","tasol");
Statement stat=conn.createStatement();
String sql= "select cif_no,id,cust_surname,cust_name,cust_add_line1,dob from cif_archive_extract where cif_archive_extract.cif_no='123456789' && cif_archive_extract.id=1234";

String sql1=" ",sql2=" ",sql3=" ",sql4=" ",sql5=" ",sql6=" ",sql7=" ",sql8=" ",sql9=" ",sql20=" ",sql21=" ",sql22=" ",sql23=" ",sql24=" ",sql25=" ",sql26=" ",sql27=" ",sql28=" ",sql29=" ",sql30=" ",sql31=" ",sql32=" ",sql33=" ",sql34=" ",sql35=" ",result= " ",sql36=" ",sql37=" ",sql38=" ";
String r1=" ",r2=" ",r3=" ",r4=" ",r5,r6,r7,r8,r9,r10,r11,r12,r13=" ",r14,r15,r16,r17,r18,r19,r20=" ",r21=" ",r22=" ",r23=" ",r24=" ",r25=" ",r28,r32=" ",r33=" ",r34,r26=" ",r27=" ",r30=" ",r31=" ",r29,r100=" ",r101=" ",r102=" ",r103=" ",r104=" ",r312=" ";
String cif=" ",id=" ",select=" ";
result=sql;
if(a1.equals("") && a19.equals("1"))
{
System.out.println("I'm here ");
// result=sql;
}
else
{
sql1=" OR cif_archive_extract.cif_no LIKE '"+a1+"%'&& cif_archive_extract.id="+a19+ "" ;
result=result+sql1;
}

if(a2.equals("") && a20.equals("2"))
{
//result=sql;
}
else
{
sql2=" OR cif_archive_extract.pre_cif_no LIKE '"+a2+"%' && cif_archive_extract.pre_id="+a20+ "";
result=result+sql2;
}
if(a3.equals("") && a21.equals("3"))
{

}

else
{
String sqlgen= "select id,account_no,cifno_primary_cust from general_archive_extract where general_archive_extract.account_no LIKE '"+a3+"%' && general_archive_extract.id="+a21+ "";
ResultSet rc = stat.executeQuery(sqlgen);

while(rc.next())
{
r30 = rc.getString("id");
r31= rc.getString("account_no");
r32= rc.getString("cifno_primary_cust");

String sql50= " OR cif_archive_extract.cif_no ='"+r32+"' && cif_archive_extract.id="+a21+ "";
result=result+sql50;

}}



if(a4.equals(""))
{

}
else
{
sql4=" OR cif_archive_extract.cust_surname LIKE '"+a4+"%'";
result=result+sql4;
}



if(a6.equals(""))
{

}
else
{
sql6=" OR cif_archive_extract.cust_name LIKE '"+a6+"%'";
result=result+sql6;
}

if(a8.equals(""))
{

}
else
{
sql8=" OR cif_archive_extract.cust_add_line1 LIKE '"+a8+"%'";
result=result+sql8;
}
if(a9.equals(""))
{

}
else
{
sql9=" OR cif_archive_extract.cust_post_code LIKE '"+a9+"%'";
result=result+sql9;
}
if(a10.equals(""))
{

}
else
{
sql20=" OR cif_archive_extract.cust_mail_add1 LIKE '"+a10+"%'";
result=result+sql20;
}

if(a11.equals(""))
{

}
else
{
sql21=" OR cif_archive_extract.cust_mailpostcode LIKE '"+a11+"%'";
result=result+sql21;
}
if(a12.equals(""))
{

}
else
{
sql22=" OR cif_archive_extract.pre_cust_surname LIKE '"+a12+"%'";
result=result+sql22;
}



if(a13.equals(""))
{

}
else
{
String sqlch= "Select account_no,cifno_primary_cust FROM cheque_facility_archive_extract WHERE cheque_facility_archive_extract.bsb_link_number LIKE '"+a13+"%'" ;
ResultSet rz = stat.executeQuery(sqlch);

while(rz.next())
{
r21 = rz.getString("account_no");
r20 = rz.getString("cifno_primary_cust");
}

sql36= " OR cif_archive_extract.cif_no ='"+r20+"%'" ;
result=result+sql36;
// System.out.println("Value for result is "+result);

}

if(a14.equals(""))
{

}
else
{
String sqlca= "Select account_no,cifno_primary_cust FROM card_archive_extract WHERE card_archive_extract.card_number LIKE '"+a14+"%'" ;
ResultSet ry = stat.executeQuery(sqlca);

while(ry.next())
{
r24 = ry.getString("account_no");
r25= ry.getString("cifno_primary_cust");
}
// System.out.println("Value for bsb_link_number"+r21);

sql37= " OR cif_archive_extract.cif_no ='"+r25+"%'";
result=result+sql37;
// System.out.println("Value for result is "+result);

}


/* if(a15.equals(""))
{

}
else
{
String sqlsav= "select id,cif_no from savings_account_archive_extract where savings_account_archive_extract.security_type ='"+a15+"%'";
ResultSet rx = stat.executeQuery(sqlsav);

while(rx.next())
{
r26 = rx.getString("id");
r27= rx.getString("cif_no");
System.out.println("Value for cif no is " +r27);
sql38= " OR cif_archive_extract.cif_no ='"+r27+"%'";
result=result+sql38;
}
} */

if(a16.equals(""))
{

}
else
{

String sqlmort= "select id,cif_no from savings_account_archive_extract where savings_account_archive_extract.volume_mortagage ='"+a16+"%'";
ResultSet rw = stat.executeQuery(sqlmort);

while(rw.next())
{
r26 = rw.getString("id");
r27= rw.getString("cif_no");
System.out.println("Value for cif no is " +r27);
String sql39= " OR cif_archive_extract.cif_no ='"+r27+"%'";
result=result+sql39;
}
}
if(a17.equals(""))
{

}
else
{

String sqlsec= "select id,cif_no from loan_account_archive_extract where loan_account_archive_extract.security_type ='"+a17+"%'";
ResultSet rv = stat.executeQuery(sqlsec);

while(rv.next())
{
r28 = rv.getString("id");
r29= rv.getString("cif_no");
System.out.println("Value for cif no is " +r29);
String sql40= " OR cif_archive_extract.cif_no ='"+r29+"%'";
result=result+sql40;
}
}

if(a18.equals(""))
{

}
else
{



String sqlmort1= "select id,cif_no from loan_account_archive_extract where loan_account_archive_extract.volume_mortgage ='"+a18+"%'";
ResultSet rv = stat.executeQuery(sqlmort1);

while(rv.next())
{
r33 = rv.getString("id");
r34= rv.getString("cif_no");
System.out.println("Value for cif no is " +r34);
String sql40= " OR cif_archive_extract.cif_no ='"+r34+"%'";
result=result+sql40;
}
}


System.out.println("Value for search is "+result);
ResultSet re = stat.executeQuery(result);

while(re.next())
{
r4 = re.getString("cif_no");
r5 = re.getString("id");
r6 = re.getString("cust_surname");
r7= re.getString("cust_name");
r8= re.getString("cust_add_line1");
r9= re.getString("dob");

session.setAttribute( "cif", r4 );
session.setAttribute( "select", r5 );

cif= (String)session.getAttribute( "cif" );
select= (String)session.getAttribute( "select" );
System.out.println("Value for select is "+select);
//Line 362
arrayList.add(new ResultRows(r4,r5,r6,r7,r8,r9));
}
}else{
arrayList = (ArrayList)session.getAttribute("arrayList");
}
// String account= (String)session.getAttribute( "cif" );
int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 10;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= "Previous";
String next = "Next";
List displayList = null;
if( null != request.getParameter("next"))
{
fromIndex = Integer.parseInt(request.getParameter("next"));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}

if( null != request.getParameter("prev"))
{
toIndex = Integer.parseInt(request.getParameter("prev"));
fromIndex = toIndex - increment;
}

if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0 )
previous = "<a href="+ uri +"?prev="+ fromIndex +"> Previous </a>";
if(toIndex != 0 && check)
next = "<a href="+ uri +"?next="+ toIndex +"> Next </a>";

%>
<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
%>

<div id="Layer6" style="position:absolute; width:961px; height:25px; z-index:43; left: 11px; top: 70px;">
<div align="left">
<table width="100%" height="20" border="0">
<tr>
<td width="11%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong></strong></font></td>
<td width="9%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><%=resultRows.getR5()%></strong></font></td>
<td width="17%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><%=resultRows.getR6()%></strong></font></td>
<td width="26%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><%=resultRows.getR7()%></strong></font></td>
<td width="22%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><%=resultRows.getR8()%></strong></font></td>
<td width="15%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><%=resultRows.getR9()%></strong></font></td>
</tr>
<%} %>
</table>
</div>
</div>
<div id="Layer3" style="position:absolute; width:200px; height:115px; z-index:43; left: 350px; top: 281px;">
<table width="100%" border="0">
<tr>
<td width="52%"><%=previous%></td>
<td width="48%"><%=next%></td>
</tr>
</table>
</div>

</div>
</div>


</DIV>
<DIV id=Layer41
style="Z-INDEX: 41; LEFT: 726px; WIDTH: 252px; POSITION: absolute; TOP: 18px; HEIGHT: 82px"><IMG
height=59 src="/archiving/images/image001.gif" width=267></DIV></BODY></HTML>
 
siberian
how do i use them.no explanation for using them

aby
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top