display search results in multiple pages, very urgent (not too difficult)

Hi all, When displaying searched for items I am displaying them in a html table. Id like the search to span into a new page when the amount of items exceeds ten and another page if it exceeds twenty etc etc. Something like how google displays multiple pages for search results. How is this possible?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

MogalManicConnect With a Mentor Commented:
Just store your query results on the session.  Are you doing the SQL querying within the JSP or are you using a Servlet?

If yours is just a simple application and it is the former then you could do something like this:


< jsp:useBean id="results" "scope="session" class="java.util.List"/>
< jsp:useBean id="pageNum" "scope="session" class="java.lang.Integer"/>
<% if (request.getMethod().equalsIgnoreCase("GET")) {%>
   <jsp:include page="query.jsp"/>
<form name='pagedForm' action='' method='post'/>

int rowIdx;
     rowIdx<results.size() && (rowIdx<(pageNum+1)*MAX_ROWS_PER_PAGE;rowIdx++) {
   ResultsBean eachRow= (ResultsBean)resultsIT.next();
     // ... code to display the results
<% if (results.size()>MAX_ROWS_PER_PAGE) {%>
<table summary="next_prev Buttons">
           <%if ((rowIdx-MAX_ROWS_PER_PAGE)>0) {%>
                   <input type='button' name='Page' value='Prev Page'/>
           <%if (rowIdx<size()) {%>
                   <input type='button' name='Page' value='Next Page'/>

< jsp:useBean id="results" "scope="session" class="java.util.List"/>
//Java code to query DB and move results into 'results' list
See if this is of any help....
SuAeEAuthor Commented:

Btw, Im using a mysql database.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

> Im using a mysql database.
Should not be a problem. You can specify the appropriate JDBC driver for MySql in the code.

SuAeEAuthor Commented:

I had a look at that and to be honest it seems too complicated for me :( . And I really cant stand sifting through large amounts of code, much rather write it myself. Any other ideas?
You could also query the database on each page.  Increment/Decrement the pageNumber and post it on the request and when the query is executed, skip the results up until the page requested:
int recNo=0;
while(pageNo*RESULTS_PER_PAGE<recNo) {
   rs.next();  //Skip results in ResultSet before requested page

Then process the results up to RESULTS_PER_PAGE.

The pageNumber could be incremented/decremented in a link like this:
<a href="pagedQuery.jsp?pageNo=<%=pageNo+1%>">Next Page</a>
<a href="pagedQuery.jsp?pageNo=<%=pageNo-1%>">Previous Page</a>
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.