GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 484 of 502    Print  
JSP Paging
Hi..
I have developed one web-page which shows ALL employee records fetched from a employee table and display them in my JSP page.
It has contain more than 1000's of records. I need to display first 10 Records in my page. There should be some 4 links below the records display which get me to see next 10 records or previous 10 records or first 10 records or Last 10 records.
IS it possible in JSP?? Can u provide me a code



  
Total Answers and Comments: 1 Last Update: July 14, 2008     Asked by: ramesh.sure 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: mini2008
 

Paging In JSP Page:
--------------------------

1. Change Your SP which is going to retrieve data by adding 2 more columns  CurrentPage,DisplayCount and the usual other Parameters
 that u have to pass.
2. while passing Parameters from Front End You have to add these Two Columns also.

3.The Code you have to use to get the Paging in JSP that i mentioned below.

4.In Inner HTML i have given example code that how u have to Pass the page Number ,Number count depending upon your code you can        change it


<%
// Variable declaration 
String gsPageNo=null; //the page no
int ginop=0; // number of pages
int lcpage=0;  //for previous page and next page
String liCurrPage=null; // current page no


// get the page number  from hidden variable
liCurrPage=request.getParameter("pageNo");
  if(liCurrPage==null)
  {
   liCurrPage="1";
  }


// check the submit value
if(gsHdSubmit!=null)   // submit value
  {
   if(gsHdSubmit.equals("prev"))
   {
    lcpage=Integer.parseInt(liCurrPage)-1;
    liCurrPage=lcpage+"";
   }
   else if(gsHdSubmit.equals("next"))
   {
    lcpage=Integer.parseInt(liCurrPage)+1;
    liCurrPage=lcpage+"";
   }
   if(gsHdSubmit.equals("0"))
    liCurrPage="1";
   else //For First Time
   {
    gsPageNo="1";
   }
  }


//while passing it through SP
   gsPageNo="1";    //set the Page Number
   String lstempArray[] = {liCurrPage+"",giDispCount+"",gsDate,gsTrans,gsUserID};  // the parameters for SP that we are going to pass


// retrieve Number of Pages from SP
    ginop=Integer.parseInt(gCRcachedrowset.getString("nop"));
    if (lbifRecords)   // checks If it is First Time You are going to Display
     {
      if(ginop>1)
      {    
%>       <script language="javascript">
        document.all["testInner"].innerHTML="<TABLE><td class=head3><input type=text size=5 name=txtpagenum value='<%=liCurrPage%>'><input type=hidden name=txtClientCode value='<%=gsClientCode%>'>&nbsp;of&nbsp;<%=ginop%>&nbsp;&nbsp;<input type=button class='stylesubmit' name=pgsubmit value=Go onclick='return fnpgsubmit("current")' onchange='fnchange()'>&nbsp;&nbsp;<input type=button class='stylesubmit' name=hdprev value='<<' onclick='return fnpgsubmit("prev")'> <input type=button class='stylesubmit' name=hdnext value='>>' onclick='return fnpgsubmit("next")'></TABLE>";
       </script>
<%      }
%>
      <script language="javascript">
 // Validation for Paging
       function fnpgsubmit(navigate)
       {
        if(navigate=="current")
        {
         if(document.frmName.txtpagenum.value=="")
         {
          alert("Enter Number !!!");
          document.frmName.txtpagenum.focus();
          return false;
         }
         if(isNaN(document.frmName.txtpagenum.value))
         {
          alert("Please Enter Numeric Value Only !!!");
          document.frmName.txtpagenum.value="";
          document.frmName.txtpagenum.focus();
          return false;
         }
         if(eval(document.frmName.txtpagenum.value)<1)
         {
          alert("Please enter page number greater than zero !!");
          document.frmName.txtpagenum.focus();
          return false;
         }
         if(eval(document.frmName.txtpagenum.value)>eval(document.frmName.hidtotal.value))
         {
          alert("Please enter page number less or equal to no of total pages!!!");
          document.frmName.txtpagenum.focus();
          return false;
         }
        }
        if(navigate=="current")
        {
         document.frmName.pageNo.value=document.frmName.txtpagenum.value;
         document.frmName.hdsubmit.value="current";
         document.frmName.submit();
        }
        else if(navigate=="next")
        {
         if(eval(document.frmName.pageNo.value)==document.frmName.hidtotal.value)
         {
          alert("Forward Limit Exceed !!");
          document.frmName.txtpagenum.focus();
          return false;
         }
         document.frmName.pageNo.value=eval(document.frmName.pageNo.value);
         document.frmName.hdsubmit.value="next";
         document.frmName.submit();
        }
        else if(navigate=="prev")
        {
         if(eval(document.frmName.pageNo.value)==1)
         {
          alert("Backward Limit Exceed !!");
          document.frmName.txtpagenum.focus();
          return false;
         }
         document.frmName.pageNo.value=eval(document.frmName.pageNo.value);
         document.frmName.hdsubmit.value="prev";
         document.frmName.submit();
        }
       }
      </script>
// Display the Table Header

      <%

      lbifRecords=false;
     }
%>

// Hidden Variables for number of pages and Current page

</table>
 <input type="hidden" name="hidtotal" value="<%=ginop%>">
 <input type="hidden" name="pageNo" value="<%=liCurrPage%>">
</form>



Above answer was rated as good by the following members:
cursin, sonalgauravmahajan
July 14, 2008 03:37:28   #1  
mini2008 Member Since: July 2008   Contribution: 1    

RE: JSP Paging

Paging In JSP Page:
--------------------------

1. Change Your SP which is going to retrieve data by adding 2 more columns CurrentPage DisplayCount and the usual other Parameters
that u have to pass.
2. while passing Parameters from Front End You have to add these Two Columns also.

3.The Code you have to use to get the Paging in JSP that i mentioned below.

4.In Inner HTML i have given example code that how u have to Pass the page Number Number count depending upon your code you can change it


<
// Variable declaration
String gsPageNo null; //the page no
int ginop 0; // number of pages
int lcpage 0; //for previous page and next page
String liCurrPage null; // current page no


// get the page number from hidden variable
liCurrPage request.getParameter("pageNo");
if(liCurrPage null)
{
liCurrPage "1";
}


// check the submit value
if(gsHdSubmit! null) // submit value
{
if(gsHdSubmit.equals("prev"))
{
lcpage Integer.parseInt(liCurrPage)-1;
liCurrPage lcpage+"";
}
else if(gsHdSubmit.equals("next"))
{
lcpage Integer.parseInt(liCurrPage)+1;
liCurrPage lcpage+"";
}
if(gsHdSubmit.equals("0"))
liCurrPage "1";
else //For First Time
{
gsPageNo "1";
}
}


//while passing it through SP
gsPageNo "1"; //set the Page Number
String lstempArray[] {liCurrPage+"" giDispCount+"" gsDate gsTrans gsUserID}; // the parameters for SP that we are going to pass


// retrieve Number of Pages from SP
ginop Integer.parseInt(gCRcachedrowset.getString("nop"));
if (lbifRecords) // checks If it is First Time You are going to Display
{
if(ginop>1)
{
> <script language "javascript">
document.all["testInner"].innerHTML "<TABLE><td class head3><input type text size 5 name txtpagenum value '< liCurrPage >'><input type hidden name txtClientCode value '< gsClientCode >'> of < ginop >  <input type button class 'stylesubmit' name pgsubmit value Go onclick 'return fnpgsubmit("current")' onchange 'fnchange()'>  <input type button class 'stylesubmit' name hdprev value '<<' onclick 'return fnpgsubmit("prev")'> <input type button class 'stylesubmit' name hdnext value '>>' onclick 'return fnpgsubmit("next")'></TABLE>";
</script>
< }
>
<script language "javascript">
// Validation for Paging
function fnpgsubmit(navigate)
{
if(navigate "current")
{
if(document.frmName.txtpagenum.value "")
{
alert("Enter Number !!!");
document.frmName.txtpagenum.focus();
return false;
}
if(isNaN(document.frmName.txtpagenum.value))
{
alert("Please Enter Numeric Value Only !!!");
document.frmName.txtpagenum.value "";
document.frmName.txtpagenum.focus();
return false;
}
if(eval(document.frmName.txtpagenum.value)<1)
{
alert("Please enter page number greater than zero !!");
document.frmName.txtpagenum.focus();
return false;
}
if(eval(document.frmName.txtpagenum.value)>eval(document.frmName.hidtotal.value))
{
alert("Please enter page number less or equal to no of total pages!!!");
document.frmName.txtpagenum.focus();
return false;
}
}
if(navigate "current")
{
document.frmName.pageNo.value document.frmName.txtpagenum.value;
document.frmName.hdsubmit.value "current";
document.frmName.submit();
}
else if(navigate "next")
{
if(eval(document.frmName.pageNo.value) document.frmName.hidtotal.value)
{
alert("Forward Limit Exceed !!");
document.frmName.txtpagenum.focus();
return false;
}
document.frmName.pageNo.value eval(document.frmName.pageNo.value);
document.frmName.hdsubmit.value "next";
document.frmName.submit();
}
else if(navigate "prev")
{
if(eval(document.frmName.pageNo.value) 1)
{
alert("Backward Limit Exceed !!");
document.frmName.txtpagenum.focus();
return false;
}
document.frmName.pageNo.value eval(document.frmName.pageNo.value);
document.frmName.hdsubmit.value "prev";
document.frmName.submit();
}
}
</script>
// Display the Table Header

<

lbifRecords false;
}
>

// Hidden Variables for number of pages and Current page

</table>
<input type "hidden" name "hidtotal" value "< ginop >">
<input type "hidden" name "pageNo" value "< liCurrPage >">
</form>


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 1Overall Rating: +1    

 Related Questions

Hi.. I have developed one web-page which shows ALL employee records fetched from a employee table and display them in my JSP page.It has contain more than 1000's of records. I need to display first 
Latest Answer : Paging In JSP Page:--------------------------1. Change Your SP which is going to retrieve data by adding 2 more columns  CurrentPage,DisplayCount and the usual other Parameters  that u have to pass.2. while passing Parameters from Front End ...


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

jQuery Completed sorting and paging code

Learning jQuery The Finished Code The completed sorting and paging code in its entirety follows mosgoogle geshibot lang php&quot; fn alternateRowColors function tbody tr odd this removeClass even addClass odd ; tbody tr even this removeClass odd addClass even ; return this; ; document
 

Java and Client Server Models

Java and Client Server Models The Role of Client Servers on the Web Client server models provide the essential mechanisms for working with the Internet In fact most of the World Wide Web is built according to this paradigm In client server models the web browsers run by millions of users are the cli
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

Using UML with Java

Using UML with Java While Java is not a new language its application for the development of embedded systems is quite new Developers are beginning to take a second look at modeling languages such as UML and many feel it can be a powerful tool in their development arsenal mosgoogle center Introductio
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

Java Technology Trends

Technology Trends Involving Java Java is an object oriented programming language OOP for Web browsers It is organized around data rather than actions and supports polymorphism which allows the same code to be written generically so it can function with different datatypes inheritance which allows on
 

HR Interview - HR Interview Mistakes You Will Want To Avoid

HR Interview Mistakes You Will Want To Avoid The job interview can be a stressful process This is especially true for those who are going after a competitive position Your nonverbal communication combined with the answers you give during the interview will determine if you are hired mosgoogle While
 

HR Interview - Behavioral HR Interviews

Behavioral HR Interviews As the name implies a behavioral interview is an interview that is held by a human resources department to determine if an applicant has the behaviors that are appropriate for a job The company must know how an applicant will behave in a certain situations mosgoogle The logi
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape