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>
Related Tutorials/Questions & Answers:
display 10 records per page in jsp - JSP-Servletdisplay 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
Advertisements
display records with images problem - JSP-Servletdisplay 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 Display Records in Tree Format - JSP-ServletDisplay 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 display results on same jsp pagedisplay 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 pagedisplay 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 pagedisplay 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 1000 of records - Strutsdisplay 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 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
display checked ckeckbox in same jsp pagedisplay checked ckeckbox in same
jsp page how to
display checked ckeckbox in same
jsp page?
Hi,
Here is the html code to
display check...
jsp page.
(for example, as it happens in VB that after clicking checkbox
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
how to display records from databasehow 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
Data displaying with limited records in jspData 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
Display image on JSP page using XML Display image on
JSP page using XML
... can
display a image on
JSP page by using XML.
This example will examine how to parse and expose XML
information using the JAXP with a
JSP page printing records from jsp - JSP-Servletprinting
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
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 date in JSP?How to
display date in
JSP? How to create a simple
JSP program which displays date on the
page?
Thanks
Hi,
You should import...() %>
Check complete tutorial at How to Create
JSP Page?
Thanks
display image using jspdisplay 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
display image on jsp is downloading on
jsp.
show i can open it. but i want to
display that image on
jsp...
display image on jsp how to
display image from database which path is coming in string.
i want to
display image and its discription and price
NEXT and PREVIOUS Records - JSP-ServletNEXT 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 Java in JSPDisplay Java in JSP please i need urgent help. How can i
display Java Applet created in netbeans in
JSP?.
the Application involves MYSQL Database connection. Thanks
image display - JSP-Servletimage display how to
display image that store in mysql database... column have BLOB datatype.... Hi Friend,
Please visit the following link:
http://www.roseindia.net/
jsp/retrieve-image.shtml
Thanks
how to display the email message in jsphow to
display the email message in jsp hi every one ..
i am new from this industry please help me to
display the email message in
jsp page please send me sample code
Jsp Image DisplayJsp 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>
dynamic display - JSP-Servlet javax.servlet.http.*;
public class DataServlet extends HttpServlet{
String
page="/
jsp...dynamic display hi,
i want to
display dynamic values in drop drown box in a
jsp page.these values are in the form of arraylist's object which
image display in jsp - Java Beginnersimage
display in jsp i uploaded the image and how can i print that image in next
jsp page.... Hi friend,
read for more information,
http://www.roseindia.net/
jsp/file_upload/employee_upload_profile_image.shtml