search
hi, I have a search method using for-loop to print out the output. like:
int numCols = rs.getMetaData().getColumnCount ();
out.println("<tr>");
for (int i=1; i<=numCols; i++) {
out.print("<td><center>" + rs.getString(i) + "</center></td>" );
}
any idea how to let the page display each 10 results in a separate page and if more than one page add next button.
thanks
[451 byte] By [
mousawia] at [2007-10-2 18:51:26]

well thanks, but my output is in the same servlet. here is the method that perform search for book by title. it is part of a large servlet(around 60 pages of code).
private void Find_Book_Title(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
try{ //try
con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
String query = "SELECT ITEM.ITEM_NO,TITLE, AUTHORS, ITEM_YEAR,LOCATION, STATUS "+
"FROM ITEM, BOOK WHERE ITEM.ITEM_NO=BOOK.ITEM_NO AND ITEM_TYPE='"+Type+"'"+
" AND TITLE LIKE '%"+Word+"%' ORDER BY TITLE";
ResultSet rs = stmt.executeQuery(query);
boolean empty=true;
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Search Result</title></head>");
out.println("<body bgcolor=#ccffff>");
out.println("<center><font color=AA0000>");
out.println("
");
out.println("<h1>TITLE SEARCH</h1>");
out.println("
<table border='1'>");
out.println("<tr><th>ITEM NO</th><th>TITLE</th><th>AUTHORS</th><th>YEAR</th><th>LOCATION</th><th>STATUS</th></tr>");
while ( rs.next() )
{
empty=false;
int numCols = rs.getMetaData().getColumnCount ();
out.println("<tr>");
for (int i=1; i<=numCols; i++) {
out.print("<td><center>" + rs.getString(i) + "</center></td>" );
}
out.println("</tr>");
}
out.println("</table>");
out.println("<table><tr>");
out.println("<td><Form name=menu action=/mhm029/Librarian_Log.jsp method=post>");
out.println("<input type=submit name=submit value=Menu></td>");
out.println("</Form><td> </td>");
out.println("<td><Form name=back action=/mhm029/find_item_title.jsp method=post>");
out.println("<input type=submit name=submit value=Back></td>");
out.println("</Form>");
out.println("</tr></table>");
out.println("</font></center>");
out.println("</body>");
out.println("</html>");
out.close();
if (empty)
{
//PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Search Result</title></head>");
out.println("<body bgcolor=#ccffff>");
out.println("<center><font color=AA0000>");
out.println("
");
out.println("<h1>TITLE SEARCH</h1>");
out.println("
<table border='1'>");
out.println("<tr><td>No results where found</td></tr>");
out.println("</table>");
out.println("<table><tr>");
out.println("<td><Form name=menu action=/mhm029/Librarian_Log.jsp method=post>");
out.println("<input type=submit name=submit value=Menu></td>");
out.println("</Form><td> </td>");
out.println("<td><Form name=back action=/mhm029/find_item_title.jsp method=post>");
out.println("<input type=submit name=submit value=Back></td>");
out.println("</Form>");
out.println("</tr></table>");
out.println("</font></center>");
out.println("</body>");
out.println("</html>");
out.close();
}
}//try
catch (Exception e) {
throw new ServletException(e.getMessage());
}
}
Despite all the annoying quirks of JSF, I think in this particular case it could be handy.
Oracle's ADF faces (and possibly Apache's myfaces framework ) allows you to put in a rangechangelistener. Also, things like sorting a table by columns is taken care of, for the most part (I did notice that it has limitations, like the sorted column must be a direct field of the current object you're working with, not nested)
A huge downside to using JSF is the steep learning curve, but once you play around with it a bit, there are a lot of available features (page scrolling & sorting being just minor features)
Good Luck!