Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Splitting a large table into multiple JSP pages

 
Mervin Chan
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with presenting my data on my JSP.

My struts app pulls some data from the DB and presents it in a table on a jsp page.
because the records may range from 1 to 1000++, depending on the user's query.

i am wondering if there is anyway, to
"save the table" and spread the data (let's say every 50 rows) on the jsp.

The user will click a "next" button to see the next 50 rows until the end.

Preferbly, I would prefer to do the SQL query once, and post-process the data, rather than
executing the SQL query n times.

Wonder if you guys can point to me the general direction of a solution.

Thanks!
 
Niki Nono
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one way i think would be to store the values returned by the query in a session variable.
disadvantage is storage space for the session.
will come back with a better solution.
 
Prakash Balasubramani
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Have a variable page.

While calling the presentation page for first page call it with value 0 for this variable. Then after fetching the resultset move record cursor page * 50 times using looping. Then display ur next set of 50 records.

Then use next butoon to call the same page with (page + 1) value for this variable.

Following is a sample code for the above said :

ResultSet rs_sample;

int toMove = Integer.ParseInt(request.getParameter("page"));

//to move record cursor to point particular page's start record

for(i=1;tomove*50;i++)
rs_sample.next();

int count = 1;

while(rs_sample.next && count <= 50)
{
// display records in your own format may be 1 record per row
}

Call samepagename.jsp with page=(toMove-1) for previous page

Call samepagename.jsp with page=(toMove+1) for next page

Hope this could be useful for u.

Bye,

B.Prakash
 
Mervin Chan
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prakash:

Thanks man.

It was quite useful.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic