• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How show page wise Results Displaying in JSP

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u very much. I have implemented the given logic and i is working very fine
Regards
Madhu Kumar
 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its ok..
bye
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic