8 Replies - 63998 Views - Last Post: 22 January 2009 - 03:56 AM Rate Topic: -----

#1 lilygrace  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 103
  • Joined: 17-August 05

JSP: Pagination help

Posted 12 December 2005 - 01:46 AM

i need some help here...I don't know where to put the pagination code in my code.

I found a JSP code for pagination but I can't understand how it works...can someone make a simple tutorial of the pagination (without using taglib)

Attach here is my JSP file..thanks!!!!

Attached File(s)


Is This A Good Question/Topic? 1

Replies To: JSP: Pagination help

#2 Amorphous  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 10-December 05

Re: JSP: Pagination help

Posted 12 December 2005 - 08:06 AM

Put at the top of each page...

Quote

<%@ page
language="java"
import=". . ."
errorPage=". . ."
contentType=". . ."
%>


http://www.webdevelo.../jsp_build.html
Was This Post Helpful? 0
  • +
  • -

#3 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: JSP: Pagination help

Posted 12 December 2005 - 08:41 AM

Amorphous, the user is referring to pagination...the concept of displaying only a certain number of results on a page, with a link to another page provided that would display a further amount. You may read about it here.
Was This Post Helpful? 0
  • +
  • -

#4 lilygrace  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 103
  • Joined: 17-August 05

Re: JSP: Pagination help

Posted 12 December 2005 - 08:40 PM

Amadeus, on 12 Dec, 2005 - 09:38 AM, said:

Amorphous, the user is referring to pagination...the concept of displaying only a certain number of results on a page, with a link to another page provided that would display a further amount. You may read about it here.

Thanks Amadeus...but I'm not using a taglib

I saw this code in Java forum

<%@ 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>



but I just don't know how to implement it to my page (uploaded in my first post) because I'm using database...

could u help me with my problem? Thanks!!!
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: JSP: Pagination help

Posted 12 December 2005 - 08:56 PM

Using a database is the same thing, except the records will be the ones returned from your query...you can approach it one of two ways: Pull a certain number of records from the db, display them, and provide a link to the next page where another set of records will be returned, or pull them all at once, display the first set, then provide a link to the same page with a flag in the querystring to indicate the next set to display.

In your code for example, you get a result set returned...rsStates. Put those results into an array../for the first page, start at index 0, and display the first 10...then provide a link to either the same page or a second page, passing the array as a hidden value, nad the index of the next element to display in the querystring (or as a hidden value)...on that page, start there and continue.

Any reason why you'd prefer not to use the tag library?
Was This Post Helpful? 0
  • +
  • -

#6 lilygrace  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 103
  • Joined: 17-August 05

Re: JSP: Pagination help

Posted 12 December 2005 - 11:46 PM

Amadeus, on 12 Dec, 2005 - 09:53 PM, said:

Any reason why you'd prefer not to use the tag library?

:unsure: :unsure: haven't done anything with taglibs actually...I'm doing purely scripting... >.< ^_^ :stupid: :(
Was This Post Helpful? 0
  • +
  • -

#7 dhoolmahi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-January 09

Re: JSP: Pagination help

Posted 22 January 2009 - 03:36 AM

Attached File  pagination_script.zip (1.62K)
Number of downloads: 2065Attached File  pagination_script.zip (1.62K)
Number of downloads: 2065

View Postlilygrace, on 12 Dec, 2005 - 10:46 PM, said:

Amadeus, on 12 Dec, 2005 - 09:53 PM, said:

Any reason why you'd prefer not to use the tag library?

:unsure: :unsure: haven't done anything with taglibs actually...I'm doing purely scripting... >.< ^_^ :stupid: :(



hi lilygrace

PFA
Can you use this for ur reference.

Thanks
Mahi
Was This Post Helpful? 0
  • +
  • -

#8 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: JSP: Pagination help

Posted 22 January 2009 - 03:44 AM

Man, the last post before yours was made over two (three) years (forgot it's 2009 now). That user hasn't been active for one year.

Btw, 18,000+ times visited thread.. Can't be true.

This post has been edited by Gloin: 22 January 2009 - 03:46 AM

Was This Post Helpful? 0
  • +
  • -

#9 dhoolmahi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-January 09

Re: JSP: Pagination help

Posted 22 January 2009 - 03:56 AM

View PostGloin, on 22 Jan, 2009 - 02:44 AM, said:

Man, the last post before yours was made over two (three) years (forgot it's 2009 now). That user hasn't been active for one year.

Btw, 18,000+ times visited thread.. Can't be true.


Gloin,

I have just gave for reference...
Old is gold....
Can you give a sample code for pagination?

Beacuse iam also having a problem in pagination

I have a page like this 1 2 3 4 5 <Next>....

Assume Currently iam in 2nd page…
If I click next …then it goes to 3 rd page…but currently it is going to last page…

Can you help me gloin?

Regards
Mahi
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1