File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes display search results as sets of pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "display search results as sets of pages" Watch "display search results as sets of pages" New topic

display search results as sets of pages

johnsep simmons

Joined: Jun 28, 2004
Posts: 1
I am using a servlet that calls a bean which does a backend query and gets some Values as Elements. I am not using JDBC connections but using JCO connections to connect to SAP and get the required table Values. I have stored the table values into an Arraylist as follows in my Servlet

ComputeSearchBean Search=new ComputeSearchBean();
ArrayList beans = new ArrayList();
for(int i=0; i<Project_Prps.getNumRows(); i++){
int j=0;

Then a call the required JSP file in which i should use the table values as

req.getSession(true).setAttribute("Search1", beans);
String url = "/Search.jsp"; //relative url for display jsp page
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(url);
rd.forward(req, resp);

My question is how to implement the JSP which will have the results diplayed as 50 elements per page. User can then use the next or previous to scroll across the webpage to see more results. How should i take care of the session so that through out the session user will see the results for his queries.
And i am talking about search results that could be 0 results or 500 results. dynamically how should i write the jsp page so that it displays them in a table in the center of the page.

Thanks and any help will be greatly appreciated.
venkat naidu

Joined: Jul 02, 2004
Posts: 2

U can handel that dynamic display with the help of java script like displaying data in the table upto 50 rows . i think u go tmy point . :roll:
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This is a classic question that comes up often. Think about some of these choices:

Execute the query, return the first 50. To display any other page execute the query, skip page*50 rows and return the next 50.

Execute the qeury, store all the results on the session. To display any page get rows starting at page*50.

Execute the query, store all the primary keys on the session. To display any page get the keys starting at page*50 and retrieve the full row data.

Execute the query and hold a cursor open. To display any page read the cursor forward or backward.

Execute the query and return the first 50. To scroll forward execute the query with key > highest key in the first 50. Maybe store the first key on each page in the session so you can scroll backward.

And Venkat's idea - retrieve all the rows clear out to the browser, maybe an XML island or hidden fields or something. Page through them with JavaScript without going to the server again.

More ... any ideas?

Lots of choices. Do any of them sound like they'd work for you?
[ July 02, 2004: Message edited by: Stan James ]

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
I agree. Here's the link:
subject: display search results as sets of pages
It's not a secret anymore!