It's not a secret anymore!*
The moose likes JSP and the fly likes How show page wise Results Displaying in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How show page wise Results Displaying in JSP" Watch "How show page wise Results Displaying in JSP" New topic
Author

How show page wise Results Displaying in JSP

Madhu Kaparapu
Ranch Hand

Joined: Jul 04, 2005
Posts: 35
i have a Search jsp page that will accept some input fields and send query to database with respective given fields . if there are 2000 relevant records in the database, the page will show the first 30 results and a next button to show succeding results or previous button for previous results, just like when we search in google.
Now my problem is i dont have any idea how to do these things. i know basic of servlets, jsp,jdbc. is there anyone resolve this problem? suggestions and ideas are most appreciated...


Regards,
Madhu Kaparapu.
Sanny kumar
Ranch Hand

Joined: May 18, 2005
Posts: 53
Hi Madhu,
use this code..
i m using oracle database..

first get the record count from the table..

if (recordcount > 0)
{
%>
<TR><td colspan=10 class=gentext align=right><B>
<%
//System.out.println("strSearch:"+strSearch);
// System.out.println("recordcount:"+recordcount);
pagecount = recordcount / recordsperpage;

if ((recordcount % recordsperpage) > 0)
pagecount = pagecount + 1;

out.println(" page count is " + pagecount + " <BR> "+"record count:"+recordcount);
prevpageno = currpageno - 1;
nextpageno = currpageno + 1;


// out.println(strSearch);
if (pagecount > 0)
{

if ( currpageno == 1)// && ( nextpageno < pagecount) )
{

if (nextpageno <= pagecount)

out.println("  <a href=\"testpage.jsp?cpageno=" + nextpageno+ "\"> Next</a>  ");
}
else if ( currpageno == pagecount)
{
if (prevpageno > 0)
out.println("  <a href=\"testpage.jsp?cpageno=" + prevpageno + "\">Prev</a>  ");
}
else
{
if (prevpageno > 0)
out.println("  <a href=\"testpage.jsp?cpageno=" + prevpageno+ "\">Prev</a>  ");
else
out.println("  Prev  ");

if (nextpageno <= pagecount)
out.println("  <a href=\"testpage.jsp?cpageno=" + nextpageno + "\">Next</a>  ");
else
out.println("  Next  ");
}

}%>

</B></td></TR>

<table>
<tr bgcolor="#e6f7ff" class="gentext" >
<td width="13%" align="center" bgcolor="#3A6EA5">
<font color="#FFFFFF"> <b>Name</TD>
<td width="13%" align="center" bgcolor="#3A6EA5">
<font color='#FFFFFF'> <b>E-mail</TD>

</TR>
<%
//out.println(strQuery);


int tempval = 0;
int moverecords = 0;

tempval = currpageno - 1;
if (tempval < 0 ) tempval = 0;

moverecords = tempval * recordsperpage -1;
out.println("welcome");
//i = 0;

if (currpageno > 1)
{
while ((rs1.next()) && (i < moverecords) )
{
i = i + 1;
}
i = i + 1;
}
while ( (rs1.next()) && (i < (currpageno * recordsperpage) ) )
{

norecs+=1;
i = i + 1;


%>

<TR bgColor=#e6f7ff>
<td width="6%" align="center"><FONt COLOR='green'><b>
<%=slno++%></TD>
<td width="6%" align="center"><FONt COLOR='green'><b>
<%=rs1.getString(1)%></TD>
<td width="6%" align="center"><FONt COLOR='green'><b>
<%=rs1.getString(2)%></TD></TR>

<%}
Madhu Kaparapu
Ranch Hand

Joined: Jul 04, 2005
Posts: 35
Thank u very much. I have implemented the given logic and i is working very fine
Regards
Madhu Kumar
Sanny kumar
Ranch Hand

Joined: May 18, 2005
Posts: 53
Its ok..
bye
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How show page wise Results Displaying in JSP
 
Similar Threads
duplicate form submission
retain search and sorting results
Cancel database query....
Submitting a table in a form
JSP Doubt