Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: Pageing in servlets


Message #1 by "Deependra Vaishnav" <vaishnav_deependra@y...> on Tue, 2 Jan 2001 12:58:53 -0000
HI
I hope this piece of source code helps you..
String Next = request.getParameter("next");
//on the
 //same servlet catching NumberFormatException change 
//the String value  to int value,like.
increment=Integer.parseInt(Next);
int total = 20 
//first find total items that can be 
//displayed,may be you can use SQL count(*) statment..

        int next;
//shows 10 items in single page  
        if (total-increment<10)
{	next = total-increment;}
			else{next =10;}  
    for(int i=0; i < next; i++) {// display all the   
first 10 values }
        increment+=10;
        if(increment > 10){
next=increment-20;out.println("<a href=\"" +
"/servlet/thesameservlet?next=" + Math.abs(next)+
"\">"+"[<<prevoius ] "+ "</a>");}
        if (increment < total )
{out.println("<a href=\"" +
"/servlet/thesameservlet?next=" + increment+ "\">"+"[
next>>]"+ "</a>");}
I hope it will work like that
take care;
Sam.

         --- Deependra Vaishnav
<vaishnav_deependra@y...> wrote:
> How i perform the paging in servlet.Paging means
> suppose if i search the
> record in table & if i found more than 20 record of
> matching criteria & i
> want to display only 10 records at a time to the
> user & after pressing the
> next button user can able to see the next records
> also program should
> display the previous button & next button ( if their
> are more records are
> available ).


--- 
NEED TECHNICAL TIPS, TOOLS, AND INSIGHTS?  Is FREE okay?
Visit EarthWeb for the latest in IT Management, Software Development, 
Web Development, Networking & Communications, and Hardware & Systems.  
Click on http://www.earthweb.com for FREE articles, tutorials,
and discussions from the experts.
---
You are currently subscribed to servlets as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-servlets-$subst('Recip.MemberIDChar')@p2p.wrox.com

  Return to Index