File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes displaying 100 rows per page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "displaying 100 rows per page." Watch "displaying 100 rows per page." New topic
Author

displaying 100 rows per page.

aliya sharma
Ranch Hand

Joined: Aug 11, 2004
Posts: 48
Hello,
I have a controller servlet that gets the resultset from Javabean and sends it to JSP to display it. JSP hangs if the result is too big (which is expected), So, im trying to show 100 rows per page. So, my Jsp will have dynamic pages depending on the amount of rows(if its 250, it will have 3 pages etc), i have achieved this. The problem is i don't know how to send only partial data per page. For example : if my query returns 250 results. My JSP wil have 1, 2, 3 on top for number of pages(this is done). 1 will display 1-100 and second one 101-200 and third one 201-250. I don't know how to achieve this. I have searched this forum, JSP and JDBC forum for the answer but haven't found anything concrete. Could anyone please guide me how to do this.
I'm using SQLSERVER 2000 as a database. I would really appreciate any help. Again, i have searched all the forums for this topic and read that as well and am still unclear. THanks for your time.

Aliya
Anupreet Arora
Ranch Hand

Joined: Jun 17, 2003
Posts: 81
Hi,

To give U a brief idea of how such a thing is implemented typically :
U need to put each record in a value object ( just a simple java bean). And as U keep on creating java bean objects of your record type, keep adding them to an arraylist. This arraylist is going to be in your http session.
So all you need to do in your jsp by default is to show the first 100 objects of that arraylist. There should be a next button on the jsp on click of which you will show 101 to 200 records and so on !!
How will U keep track of records index ?
Just keep two more variables in your session. startIndex and endIndex. The default values will be 1 and 100 respectively. So the JSP will refer to these variable to determine the which records from the arraylist to show. On click of Next add 100 to both the session variables. So the JSP should show the next hundred records.

Hope this helps...
Cheers
Anupreet
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Here are some notes on prior conversations about paging:


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
aliya sharma
Ranch Hand

Joined: Aug 11, 2004
Posts: 48
THanks Anupreet and Stan,
I have solved this problem. Stan, i did read that discussion earlier and that what helped me get started...THanks again.

Aliya
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
So don't leave us hangin ... how did you do it?
ernest fakudze
Ranch Hand

Joined: Aug 27, 2001
Posts: 216
Hi guys,

I've also been curious about how this is done for a long time. First time I tried to build such a thing I failed because I did not have my thinking cap on . I needed it for my guestbook at www.ernieboy.com. So I tried again two days ago with a new approach. In fact, I used a method which is similar to yours Anupreet where I store all the records in a session and then scroll through them. This is a jsp that I used to put this thing together and it demonstrates the basics of how it works. You can download the source code from here, it runs as is. Any constructive criticism of the code is welcome so that you can help me be a better developer.

My question. If I had 10000 records in that db, wouldn't this method be a drawback since everyone that asks for my guestbook will have a Vector with 10000 records in it? Doesn't this affect server memory? Of course, the other way to go is to use some sort of a scrollable result set as already mentioned but this also has overhead since we are hitting the databse for every N records we need. At least the data is not stale though like when using the vector in a session. So what is better guys?

[ October 23, 2004: Message edited by: ernest fakudze ]
[ October 23, 2004: Message edited by: ernest fakudze ]

In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer
Anupreet Arora
Ranch Hand

Joined: Jun 17, 2003
Posts: 81
Hello Ernest !!

If I had 10000 records in that db, wouldn't this method be a drawback since everyone that asks for my guestbook will have a Vector with 10000 records in it? Doesn't this affect server memory?


U are quite right ..but a typical case where such applications are required is when a user searches for some records. So I will design my application in such a manner that the user is kind of forced to give search criteria which restircts the records returned to a more managable number...
Practically, its not feasible for a user to browse 10000 records...so u will have a search screen where the user will give some primary search criterion...and ur database query will have the where clauses built out of those and hopefully the search will return a smaller result set ... to the eventual goal of less of memory consumption in the session or server and also the ease of browsing the resultset ..

Hope this makes sense...

I haven't explored the approach II Stan mentioned in his alogorithms ...that involves caching the result set.. can anyone give me a lead on how to implement such a thing...any links etc..
aliya sharma
Ranch Hand

Joined: Aug 11, 2004
Posts: 48
Hello,

I used the first approach mentioned in Stan's post.


I could records upto 60,000 with no difficulty and within no time.

Aliya
 
Consider Paul's rocket mass heater.
 
subject: displaying 100 rows per page.