Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: retrieving 10 records per page in jsp


Message #1 by "andrew philip" <andrewphilip@m...> on Tue, 16 Oct 2001 15:16:49
andrew

you could either control your sql statement doing:
 " select top <your_limit>
                        table_name.field  from table_name 
where table_name.field  not in 
                    (select top <your_offset> table_name.field from 
table_name )"

where your_limit and your_offset are passed as parameters from the next 
and back jsp.

depends on your data, i prefer to use an object (a simple bean ) to 
represent the record of  data from the database , add it to the vector
and store the vector in the session. then the user  loops on the results  
in the session and you dont need the DB at least for a while.

in both cases you could do with the following variables in your page:

int numberToShow=10;
int offset = 0;

in your links for next and back you should pass parameters that will tell 
how many results were seen already. 
so include a parameter like "itemNum" with the number of the last record 
use (offset+numberToShow).

when you handle the request then if it's "next" the new offset is   
offset = Integer.parseInt(request.getParameter("ItemNum"));

if it's "back": offset= Integer.parseInt(request.getParameter("ItemNum")) -
   numOfResultToShow ;

and so forth...

tips: 
if you use the vector and the session make sure you remove the vector from 
the session at the end, and beware of NullPointerException when you loop 
on the vector.
make sure you update your next and back links proparly so if you view the 
last 6 results out of 76 not to show the next one ( first cause there is 
no point in that and second is that nullpointerexception)or in the first 
page where you show between 0-10 not to show the back link.

it's not the code but, hope it helped you.
shai 


  Return to Index