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

Posted on 2004-09-21
Last Modified: 2010-04-01
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?
Question by:SuAeE
  • 2
  • 2
  • 2
  • +1

Expert Comment

ID: 12110479
See if this is of any help....

Author Comment

ID: 12110497

Btw, Im using a mysql database.

Expert Comment

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 21

Accepted Solution

MogalManic earned 175 total points
ID: 12110647
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);
     // ... 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

Author Comment

ID: 12110651

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?
LVL 35

Assisted Solution

TimYates earned 175 total points
ID: 12110758
LVL 21

Expert Comment

ID: 12110781
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) {;  //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>

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How To Remove a Principal from HttpServletRequest 4 53
Fisheye tool 2 121
JavaScript parse form with colon separated values 2 78
spring maven example issues 3 37
Direct mail marketing is the act of mailing materials straight to prospective customers. This wide form of marketing is one of the oldest methods of communicating with a geographic based demographic. So is it useful in 2017 and beyond?
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question