Home Answers Viewqa JSP-Servlet display 10 records per page in jsp

 
 


priya
display 10 records per page in jsp
3 Answer(s)      3 years and 8 months ago
Posted in : JSP-Servlet

View Answers

October 8, 2009 at 1:59 PM


Hi Friend,

Try the following code:

pagination.jsp:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%!
public int nullIntconvert(String str){
int num=0;
if(str==null) {
str="0";
}
else if((str.trim()).equals("null")) {
str="0";
}
else if(str.equals("")) {
str="0";
}
try{
num=Integer.parseInt(str);
}
catch(Exception e) { }
return num;
}
%>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";;, "root");
ResultSet rs1 = null;
ResultSet rs2 = null;
PreparedStatement ps1=null;
PreparedStatement ps2=null;

int showRows=10;
int totalRecords=10;
int totalRows=nullIntconvert(request.getParameter("totalRows"));
int totalPages=nullIntconvert(request.getParameter("totalPages"));
int iPageNo=nullIntconvert(request.getParameter("iPageNo"));
int cPageNo=nullIntconvert(request.getParameter("cPageNo"));

int startResult=0;
int endResult=0;
if(iPageNo==0) {
iPageNo=0;
}
else{
iPageNo=Math.abs((iPageNo-1)*showRows);
}
String query1="SELECT SQL_CALC_FOUND_ROWS * FROM student limit "+iPageNo+","+showRows+"";
ps1=conn.prepareStatement(query1);
rs1=ps1.executeQuery();

String query2="SELECT FOUND_ROWS() as cnt";
ps2=conn.prepareStatement(query2);
rs2=ps2.executeQuery();
if(rs2.next()) {
totalRows=rs2.getInt("cnt");
}
%>
<html>
<h3>Pagination of JSP page</h3>
<body>
<form>
<input type="hidden" name="iPageNo" value="<%=iPageNo%>">
<input type="hidden" name="cPageNo" value="<%=cPageNo%>">
<input type="hidden" name="showRows" value="<%=showRows%>">
<table width="100%" cellpadding="0" cellspacing="0" border="1" >
<tr>
<td>Roll No</td>
<td>Name</td>
<td>Marks</td>
<td>Grade</td>
</tr>
<%
while(rs1.next()) {
%>
<tr>
<td><%=rs1.getInt("rollNo")%></td>
<td><%=rs1.getString("name")%></td>
<td><%=rs1.getInt("marks")%></td>
<td><%=rs1.getString("grade")%></td>
</tr>
<%
}
%>
<%
try{
if(totalRows<(iPageNo+showRows)) {
endResult=totalRows;
}
else{
endResult=(iPageNo+showRows);
}
startResult=(iPageNo+1);
totalPages=((int)(Math.ceil((double)totalRows/showRows)));
}
catch(Exception e){
e.printStackTrace();
}
%>
<tr>
<td colspan="3">
<div>

October 8, 2009 at 2:00 PM


continue............

<%
int i=0;
int cPage=0;
if(totalRows!=0) {
cPage=((int)(Math.ceil((double)endResult/(totalRecords*showRows))));

int prePageNo=(cPage*totalRecords)-((totalRecords-1)+totalRecords);
if((cPage*totalRecords)-(totalRecords)>0){
%>
<a href="pagination.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
<%
}
for(i=((cPage*totalRecords)-(totalRecords-1));i<=(cPage*totalRecords);i++){
if(i==((iPageNo/showRows)+1)){%>
<a href="pagination.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
<%
}
else if(i<=totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>"><%=i%></a>
<%
}
}
if(totalPages>totalRecords && i<totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a>
<%
}
}
%>
<b>Rows <%=startResult%> - <%=endResult%> Total Rows <%=totalRows%> </b>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<%
try{
if(ps1!=null){
ps1.close();
}
if(rs1!=null){
rs1.close();
}

if(ps2!=null){
ps2.close();
}
if(rs2!=null){
rs2.close();
}

if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>

In the above code,we have taken the database table student(rollNo,name,marks,grade).

Thanks

September 1, 2012 at 3:28 PM


int totalRows=nullIntconvert(request.getParameter("totalRows")); int totalPages=nullIntconvert(request.getParameter("totalPages")); int iPageNo=nullIntconvert(request.getParameter("iPageNo")); int cPageNo=nullIntconvert(request.getParameter("cPageNo"));

please tell me from where these lines have come from i.e request.getParameter("totalPages") and so on.









Related Pages:
display 10 records per page in jsp - JSP-Servlet
display 10 records per page in jsp  hello, can i get a code that displays 10 records per page from a table student and when i click on the next button it displays the next 10 pages and so on. Im using jsp and mysql database
large nuber of records display to jsp - Development process
to a jsp page using pagination. I want to display 1oo records per page, remaining... that will display the records to jsp page using pagination.Here we have specified 10 records per page.Try the following code: pagination.jsp
code to display 20 record per page and display page 1,2,3,4 as recoerd increase - JSP-Servlet
code to display 20 record per page and display page 1,2,3,4 as recoerd increase  Here is my code i wnat to diplay 15 to 20 records per page please... and previous button or display page no 1,2,3.. this is my code please any one
How to display mysql database records as per clock timing?
How to display mysql database records as per clock timing?  I want to display database records as per clock timing
please give me solution how to display next page after 20 records ? - JSP-Servlet
please give me solution how to display next page after 20 records ?  Java Servlet Paging control example  here i have attached one example..." } } } 1 2 3 4 5 6 7 8 9 10
display records with images problem - JSP-Servlet
display records with images problem  hello, i am developing HR application whereby i want to display employee records and their pictures on web... with a unique id. Also i wrote i jsp that link to servlet in order to display
retrieving newly added records from mssql database and display in a jsp
these 10 records from the jsp and retrieve the next recently added 10 records...retrieving newly added records from mssql database and display in a jsp  Here is my requirement, I have to retrieve recently added 10 records
display 1000 of records - Struts
display 1000 of records  how to display 1000 of records using next... that we can display any number of records. Implement a sample   We have pagination concept in Java. Using that we can display any number of records
display the hidden text from that row, when onclick on a row of 1- 10
display the hidden text from that row, when onclick on a row of 1- 10  Using JSP: I'm displaying a set of values from the databse in a table rows (1 to 10)in jsp page, when onclick on one of the view row, it has to submit
Data displaying with limited records in jsp
Data displaying with limited records in jsp  How to display table with limited 10 records , after clicking next button another 10 records from database upto last record please help me
NEXT and PREVIOUS Records - JSP-Servlet
NEXT and PREVIOUS Records  Dear Sir, In my Project i have next and previous buttons at bottom of my page which is working fine.But as per our requirement next,previous buttons should be placed at top of the page as well
Display Records in Tree Format - JSP-Servlet
Display Records in Tree Format   hi i want to displays data in the tree format with root nodes, child nodes and leaf nodes in a jsp file... we have to pass values of root node subnodes and the leaf node to next jsp
Combobox jsp from 0 to 10
Combobox jsp from 0 to 10  Hi guys please help me to write a very easy program using jsp to display value in combobox from 0 to 10. How to write...;% for(int i=0;i<=10;i++){ %> <option value="<%=i%>"><%=i%><
Retrieving newly inserted records and displaying in jsp forever
those records in the jsp. If the session-duration exceeds 10 minutes for any...Retrieving newly inserted records and displaying in jsp forever  Sir, here is my requirement, First i have to retrieve newly added 10 records from
display checked ckeckbox in same jsp page
display checked ckeckbox in same jsp page  how to display checked ckeckbox in same jsp page?   Hi, Here is the html code to display check... ,selected checked checkboxes in another table in same jsp page. (for example
Upload and display image and text records using JSP and Oracle
Upload and display image and text records using JSP and Oracle  Hi all, I'm using JSP and Oracle 10g. I could retrieve and display records from database. But i couldnot retrieve and display image. I want to store
to display NEXT and previous option after 10 entries in java
to display NEXT and previous option after 10 entries in java  As after jsp code we refer to java for connectivity and i want that directly only 10 entries will be open and next there will be pages. so what would i do for coding
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
Java Programming: Chapter 10 Quiz
Quiz Questions For Chapter 10 THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 10 of this on-line Java textbook. You should.... Explain what this means and why it is true. Question 10: Write a complete
Jsp Image Display
Jsp Image Display  Hi,i need to display image in a Box like... to save it in a database....Kindly post JSP codes..Its Urgent, I m very thankful t... on the browser. 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD>
Java Programming: Chapter 10 Exercises
Programming Exercises For Chapter 10 THIS PAGE CONTAINS programming exercises based on material from Chapter 10 of this on-line Java... that are available on the server and display the list on standard output. Get a copy
How to display a record containing 30 fields in jsp without scrolling the page horizontally?
How to display a record containing 30 fields in jsp without scrolling the page horizontally?  I want to display records containing 30 fields in a table row.Is it possible in jsp without scrolling the page horizontally
The Page Directive in JSP Page
JSP Page.</title></head> <body> <font size="10"... The Page Directive in JSP Page     ... of the JSP page which works for the entire JSP page. These directives apply different
Display image
Display image  How to Pass image from html to jsp and display that image using jsp   Here is an example that pass an image path from the html page to jsp page and display it. 1)page.html: <%@ page language="java
How to check no records - JSP-Servlet
project, in that how i have 2 check no records. I saw an answer... to check and display your cart is empty.... PLs help me......... Reply... not empty //display something else //false resultset empty //display something
How to Display jrxml file on JSP page???
How to Display jrxml file on JSP page???  I made jrxml file using jasper report but how to display on jsp page?? i tried lot but still i didnt find out solution.so pls help me as soon as possible
JSP - JSP-Servlet
getting the data. i dont have any problem with that.. but i want to display 10 records per page. Just like google and the remaining records in next page. i want 1234 as a links at the bottom of the page... Pls..Help me... thanks in advance
printing records from jsp - JSP-Servlet
printing records from jsp  Hi Plz tell me how to printing out pages from jsps with page numbers Thank you  Hi friend, For paging in Jsp visit to : http://www.roseindia.net/jsp/paging.shtml http
jsp
(IPropertyNames.PROP_NAME_NOOF_RECORDS_PER_PAGE)); String context...jsp  p>in my project i have following jsp in this jsp the pagesize... them to pagesize how can i do this please help me <%@ page contentType
displaying List of records from database in a jsp using ajax
displaying List of records from database in a jsp using ajax  Sir, I need to retrieve the records from the database for every 7 seconds and display those records in a jsp.Following is my code. x.jsp: <%@page import
How to display content in same page while selecting fron dropdown list
How to display content in same page while selecting fron dropdown list ...),then it want to display all records from table specific to that rollno in that same... at the JSP page will be interpreted by the browser, first. You can use Javascript
how to display records from database
how to display records from database  I want to display records from database in tables, the database is having 2000 records and i want to display 20 records at a time and to use next and previous link buttons to show
Java Programming: Chapter 10 Quiz Answers
Sample Quiz Answers For Chapter 10 THIS PAGE CONTAINS SAMPLE ANSWERS to the Quiz on Chapter 10 of this on-line Java textbook. Note... is it used? Answer: A url is an address for a web page (or other information
s per ur answer
s per ur answer  i cannot understand please explain in detail 3... for jsp and servlet applications. A web application folder has to be created...) | |-----jsp |-----classes(servlet classes
How to display jfreechart at specified place in jsp
How to display jfreechart at specified place in jsp  I have a jsp page where i need to display the chart at specified position... of the jsp page is not displaying.... Below is my code. DefaultPieDataset
Backup selected records into txt file
Backup selected records into txt file       Backup selected records into txt file is used to copies the selected records or rows from a table into text file. Further, the text file
pagination in JSP - JSP-Interview Questions
employee"); I want to display those records 10 per page. Any help pls..._page = 0; int per_page = 10; String name=""; if(offset>1){ ofset = offset*per_page-per_page; } System.out.println
Retrive values from an arraylist and display in a jsp?
Retrive values from an arraylist and display in a jsp?  Hi, I need help in jsp to display values of an ArrayList in jsp. There is a java file containing a method which is returning an ArrayList. I want to display the records
Clearing the output on the web page generated by a jsp
and display those records on the web page using jsp(display.jsp) and if these records modified inside the database table, i have to display those updated records on the web page using same jsp(display.jsp). Please help me in resolving this problem
Retrive values from an arraylist and display in a jsp?
Retrive values from an arraylist and display in a jsp?  Hi, I need help in jsp to display values of an ArrayList in jsp. There is a java file containing a method which is returning an ArrayList. I want to display the records
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me   displaying List of records from database in a jsp using ajax, onclick it should display the results
displaying images and records problem - JSP-Servlet
it, all what i want is to display staff records and their pictures on the web pages...displaying images and records problem  hi, Thanks for your reply... display any record and image. I posted my question and since then no replay
displaying employee records and their images problem - JSP-Servlet
displaying employee records and their images problem  hi, Thanks for your reply to my question. The code you sent to me yesterday was not working. it doesn't display any record and image. Please, help me out urgent
Request header display in a jsp page
Request header display in a jsp page  ... to display request header information in a jsp page. When user request... to a jsp. In this example, request_header_jsp.jsp is used to display header
JSP Code - JSP-Servlet
display in the table. For example, if i have 1000 records in my table & want to display only 10 records per pages in jsp, then how can i achieve this concept... of JSP page Roll No Name Marks Grade
display image using jsp
display image using jsp  display image using jsp and phonegap on emulator of eclipse   Here is a simple jsp code that displays an image on browser. <%@ page import="java.io.*" %> <%@page contentType="image/gif
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
How to display Jfreechart from servlet in jsp web page at specified location
How to display Jfreechart from servlet in jsp web page at specified... to display the chart in web page. I generated the chart using Jfreechart... in jsp web page . Thank you very much Sir

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.