pagination in JSP

pagination in JSP

View Answers

November 17, 2008 at 7:01 AM

Hi friend,

<%@ page language="java" import="java.sql.*;"%>

<html>

<head>

<style>

A:hover {



text-decoration: none;

font-family:arial;

font-size:12px;

color: #000000;

BORDER: none;



}

A {



text-decoration: underline;

font-family:arial;

font-size:12px;

color: #000000;

BORDER: none;



}



</style>

</head>

<body>

<br><br><br>

<%

int offset=0;

int ofset = 0;

if(request.getParameter("offset")!=null) {

offset= Integer.parseInt(request.getParameter("offset").toString());

}





int total_count = 0;

int total_page = 0;

int per_page = 10;

String name="";

if(offset>1){

ofset = offset*per_page-per_page;


}



System.out.println("ofset" + ofset);

System.out.println("MySQL Connect Example.");

Connection conn = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";

String color = "#F9EBB3";



try {

Class.forName(driver);
conn = DriverManager.getConnection(url+db,userName,password);



Statement stcount = conn.createStatement();

String strQuerycount = "select count(*) from Userdetail ";

ResultSet rscount = stcount.executeQuery(strQuerycount);

if(rscount.next()){

total_count=rscount.getInt(1);

}



if(total_count%per_page==0){

total_page = total_count/per_page;

}

else{
total_page = total_count/per_page+1;
}

// System.out.println("total_page" + total_page);


Statement st = conn.createStatement();

String strQuery = "select * from Userdetail limit "+ofset+","+per_page;

// out.println(strQuery);



ResultSet rs = st.executeQuery(strQuery);

// out.println("offset " + offset);

int count=0;

if(offset>1)

// count=offset*per_page-per_page;



%>



<br><br><br>

<table width="900px" align="center" style="border:1px solid #000000;" >

<tr>

<td colspan=8 align="center" style="background-color:ffeeff"><b>Display Page</b></td>

</tr>

<tr style="background-color:efefef;">

<td><b>SNo</b></td>

<td><b>User Id</b></td>
<td><b>User Name</b></td>
<td><b>LastName</b></td>
<td><center><b>E-mail</b></center></td>
<td><b>Date Of Birth</b></td>
<td><b>Country</b></td>
<td><b>State</b></td>



</tr>

<%
while(rs.next()){
if((count%2)==0){
color = "#eeffee";
}
else{
color = "#F9EBB3";
}
count++;
%>

November 17, 2008 at 7:03 AM

<tr style="background-color:<%=color%>;">

<td><%=count%></td>

<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>

</tr>
<%
}
%>
</table>
<br><br>
<table width="100px" align="center" border=0><tr>
<%
if(count==0){
%>
<tr style="background-color:<%=color%>;">
<td colspan=8 align="center">No Record</td>
</tr>
<%
}
System.out.println("Connected to the database");
conn.close();
rs.close();
System.out.println("Disconnected from database");

}
catch (Exception e){

e.printStackTrace();

}

if(offset>1) {
int previous = offset-1;
System.out.println("previous>>>>>>>>> " + previous);

%>
<td>
<a href="viewTransAction.jsp?offset=<%=previous%>">Previous</a></td>

<%
}



if(total_page>0){

for(int i=1;i<=total_page;i++) {


if(request.getParameter("offset")==null) {
offset=1;
}
if(i==offset) {
%>
<td>
<%=i%>

</td>

<%
}
else{ %>
<td>
<a href="viewTransAction.jsp?offset=<%=i%>"><%=i%></a></td>
<%
}
}}
if(offset<total_page){
int next = offset+1;
%>
<td>
<a href="viewTransAction.jsp?offset=<%=next%>">Next</a></td>
<%
}

%>
</tr>
</table>
</body>
</html>
---------------------

Visit for more information.

http://www.roseindia.net/jsp/

Thanks.

Amardeep









Related Tutorials/Questions & Answers:
jsp pagination
jsp pagination  I want to implement pagination on jsp page Each jsp page having some radio buttons, on click of next previous page selected radio buttons are reset. I want to maintain state of selected radio buttons on previous
Pagination in jsp - JSP-Servlet
Pagination in jsp  I need an example of pagination in JSP using display tag
Advertisements
JSP Pagination
I could possibly use??   JSP Pagination pagination.jsp: <%@ page..."); } %> <html><h3>Pagination of JSP page</h3> <body><...JSP Pagination  Hi , I have several JSP's that displays data from
Jsp pagination - JSP-Servlet
tell me the solution  Hi friend, For Jsp pagination application visit to : http://www.roseindia.net/jsp/paging.shtml Thanks...Jsp pagination  Iam doing a online exam application for this i need
pagination - JSP-Servlet
friend, Simple pagination in jsp Simple pagination in JSP... Simple pagination in jsp Displaying Records...pagination  Hi, could u tell me how i will handle pagination
pagination in jsp - JDBC
. Simple pagination in jsp... ------------------   Simple pagination in jsp Simple pagination in JSP Displaying Records
dynamic pagination in jsp - JSP-Servlet
dynamic pagination in jsp  i am unable to display the data in multiple pages. I am gettting data from the database from the javaBeans to jsp by vectors... but i am unable to displaying them in jsp 15 records per page
Pagination - JSP-Servlet
Pagination  I want to display only 10 records but my arraylist contains for example about 100 records... My jsp page should contain 10 records along with the pagination below.... like prev 1 2 3 4 5 next I am using
pagination in hibernate with jsp
pagination in hibernate with jsp  Hi, plz give me example on pagination .   Hi Friend, Visit HereADS_TO_REPLACE_1 Thanks
pagination in hibernate with jsp
;html> <h3>Pagination of JSP page</h3> <body> <form>...pagination in hibernate with jsp  Hi, plz give me example on pagination .   Hi Friend, We have used MySql database with JSP.ADS
pagination in JSP - JSP-Interview Questions
pagination in JSP  Hi! Everybody.. I am new to JSP. I am doing project using JSP. Everything is OK. When i am displaying the data from ResultSet... --------------------- Visit for more information. http://www.roseindia.net/jsp/ Thanks
Jsp table Pagination
Jsp table Pagination  I tried the code already.But I dont want it with SQL.I want it for oracle database because I'm using oracle.So please help me with this issue. Thanks
pagination problem - JSP-Servlet
pagination problem   Thanks sir for posting the answer.But i have 2 problems 1.i have created one employee class in that i use getter and setter...(),my problem is that where i have to put & how to do pagination? my code
pagination problem - JSP-Servlet
pagination problem  Thanks sir for posting the answer.But i have 2 problems 1.i have created one employee class in that i use getter and setter...(),my problem is that where i have to put & how to do pagination? my code
Pagination
Pagination  How to create pagination in jsp with EJB using MS SQL
Pagination
Pagination  How to apply pagination in JSP. Please help
Pagination in jsp using oracle and not sql
Pagination in jsp using oracle and not sql  I need the code for pagination in jsp using oracle. I already tried it with rownum between instead...;Pagination of JSP page</h3> <body> <form> <input type
pagination
pagination   Simple way for pagination in jsp using java script to display data without send database
Pagination with condition using servlet or jsp
Pagination with condition using servlet or jsp  Hi, Thanks in advance. I have a requirement like this, In front-end page I have one text...")", Then I want perform the pagination based on the string value(I mean pagination
Pagination
Pagination  I want to know how to use pagination in jsp. I have a list object from that i want to display 3 questions per page can u help me
pagination
pagination  How to set pagination using java script to display data
Pagination
Pagination  How to implement pagination in struts using hibernate
In pagination how to hilight the links - JSP-Servlet
In pagination how to hilight the links  Dear Sir, Thanks for posting the answer,its working fine.Now i want google or others like pagination ,in that if i click on a number only that number color will be changed like
What's wrong with my pagination code in JSP?
What's wrong with my pagination code in JSP?  Dear experts, I've...; print("code sample");   JSP Pagination The given code retrieves...()){ totalRows=rs2.getInt("cnt"); } %> <html><h3>Pagination of JSP
Pagination
Pagination  Is their plug n play approach for creating pagination? 1) Server side as well as client side
Pagination
Pagination  I want to write one where condition in sql query in pagination concept
In pagination how to hilight the links - JSP-Servlet
In pagination how to hilight the links  Dear Sir, In pagination how to highlight the links or how to change the color of that link when i clickon that particular link....Please help me sir.. Some of the code which i
pagination
....   Here is a simple jsp pagination code where we have used mysql database...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP...pagination  I need to give pagination with where condition (query
Pagination
=rs2.getInt("cnt"); } %> Pagination of JSP page Terr_Code Terr_Name
pagination
pagination  I need to give pagination with where condition (query="select * from qtn where qid='"+replyQuesionId+"'limit "+iPageNo+","+showRows+"" ) like this I want, without where condition it is working but with condition
pagination
;Pagination of JSP page</h3> <body> <form> <input type="hidden... me how to paginate questions without refreshing page   Here is a jsp code of pagination. In the given code,we have taken the database table student
pagination
pagination  how can i start pagination in jsp?   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import...;Pagination of JSP page</h3> <body> <form> <input type="hidden
Pagination
Pagination  pagination in jsp   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import="java.sql.*" %>...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
pagination
pagination  please let me know how to fetch records from database and display them using paging in jsp and struts
Hibernate JSP
In this section, you will learn about Hibernate with JSP using simple pagination example
pagination in jsf
pagination in jsf  Hi , i am implemeting an online exam system , i have placed my questions as an arraylist in my jsp file within tag , but now i want to paginate these questions based on respective questions by clicking
Pagination in java
Pagination in java  How to handle pagination when there are records like say in millions in java? Or do we handle this using SQL? I as asked... far good performance then Java pagination. Thanks
jsf pagination
()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP... on please give any solution . Thanks, Bhuban   Here is a jsp code of pagination. In the given code,we have taken the database table student(rollNo,name,marks
Hibernate Pagination
In this tutorial we will discuss concept of pagination in hibernate
Pagination
Pagination
Pagination Using Displaytag Lib
Pagination Using Displaytag Lib  I am using Struts 1.2 for my web based project. While using display tag lib in jsp for pagination, is there any substitute of using As I dont want to be dependent on any site(s). Please
JTable Pagination
JTable Pagination  Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement pagination for the same. Can someone please help me out with this ? I have tried out many things from
Two Pagination in one page
Two Pagination in one page  hai friends any one help me. how do u make two pagination script in same page i'm used some ajax coding one pagination script is working but another pagination is not working please help me urgent
Pagination example with html code
Pagination example with html code  Hi, could u please provide pagination code with clear cut explanation. Thanks in advance
Pagination Example
; Step 3: Create a JSP page that contains pagination code: Here...; In this section, you will learn how to create pagination in struts 2. For creating pagination in your application follows the certain steps: Download
pagination+dynamic pagesize+hibernate - Struts
pagination+dynamic pagesize+hibernate  pagination using hibernate with dynamic page size plzz heilp me
Pagination without using database in php
Pagination without using database in php  How can I show multiple images in multiple rows with pagination in php
Paging or pagination - Development process
Paging or pagination  1.how to do paging or pagination in jsp using... to get a correct values... I m sending my jsp code also please help me sir...("Starting index is "+startIndex); %> Pagination The Following
store pagination form fields - Struts
store pagination form fields   hi,iam working online exams project... table. here iam using pagination for questions to be displayed to client... approach this task. iam using jstl in jsp to iterate the list object of different

Ads