pagination

pagination

i want to make online exam server by jsf 1.2 please tell me how to paginate questions without refreshing page

View Answers

July 30, 2012 at 11:14 AM

Here is a jsp code of pagination. In the given code,we have taken the database table student(rollNo,name,marks,grade).

<%@ 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>
<%
}
%>

July 30, 2012 at 11:16 AM

continue..

<%
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>
<%
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();
}
%>

Save the code with the name pagination.jsp.

Hope that it will be helpful for you.


July 30, 2012 at 3:53 PM

here problem is that : suppose i have 10 questions and i make 1 page per question . if user click on 1st question and checked the answer after moving to 2nd question this page is refreshing by which last data is lost

i dont want to forward data to next page by refreshing , i want to stop refresh in page









Related Tutorials/Questions & Answers:
Pagination
Pagination  How to create pagination in jsp with EJB using MS SQL
Pagination
Pagination  How to implement pagination in struts using hibernate
Advertisements
Pagination
Pagination  How to apply pagination in JSP. Please help
pagination
pagination  How to set pagination using java script to display data
pagination
pagination   Simple way for pagination in jsp using java script to display data without send database
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
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  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  I need to give pagination with where condition (query.......   Here is a simple jsp pagination code where we have used mysql database...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
Pagination
=rs2.getInt("cnt"); } %> Pagination of JSP page Terr_Code Terr_Name
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
code of pagination. In the given code,we have taken the database table student...;Pagination of JSP page</h3> <body> <form> <input type="hidden
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
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
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
Hibernate Pagination
In this tutorial we will discuss concept of pagination in hibernate
pagination
Pagination
Pagination
Pagination in jsp - JSP-Servlet
Pagination in jsp  I need an example of pagination in JSP using display tag
JSP Pagination
to be shown, I want to implement Pagination.. Can someone show me a sample code which I could possibly use??   JSP Pagination pagination.jsp: <%@ page..."); } %> <html><h3>Pagination of JSP page</h3> <body><
jsf pagination
of pagination. In the given code,we have taken the database table student(rollNo,name,marks...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
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 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 example with html code
Pagination example with html code  Hi, could u please provide pagination code with clear cut explanation. Thanks in advance
pagination - JSP-Servlet
pagination  Hi, could u tell me how i will handle pagination... friend, Simple pagination in jsp Simple pagination in JSP... Simple pagination in jsp Displaying Records
pagination in jsp - JDBC
pagination in jsp  Hi, I have millions of records in my oracle d... in advance...   Hi friend, This is simple code of pagination. Simple pagination in jsp
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
Pagination in PHP code - PHP
Pagination in PHP code  3.Pagination in PHP codeIs it possible to get the paging in PHP without database call? How will I show the image instead of numbering? any code that can help
pagination in php - Ajax
pagination in php  i want to fetch my data base in view page...i hav done pagination... i don't want the order....like... 1 2 3 4 . . . last i want the order in... 1 2 3 4 5 6 7
Pagination in struts 2
Pagination in struts 2  Hi, I have one question regarding pagination in struts 2 I saw one of your code that you explain here:- http... me or guide me what other option i have to use pagination in struts 2 without
ModuleNotFoundError: No module named 'apistar-pagination'
ModuleNotFoundError: No module named 'apistar-pagination'  Hi, My... named 'apistar-pagination' How to remove the ModuleNotFoundError: No module named 'apistar-pagination' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'codingsoho-pagination'
ModuleNotFoundError: No module named 'codingsoho-pagination'  Hi...: No module named 'codingsoho-pagination' How to remove the ModuleNotFoundError: No module named 'codingsoho-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'codingsoho-pagination'
ModuleNotFoundError: No module named 'codingsoho-pagination'  Hi...: No module named 'codingsoho-pagination' How to remove the ModuleNotFoundError: No module named 'codingsoho-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'codingsoho-pagination'
ModuleNotFoundError: No module named 'codingsoho-pagination'  Hi...: No module named 'codingsoho-pagination' How to remove the ModuleNotFoundError: No module named 'codingsoho-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-pagination'
ModuleNotFoundError: No module named 'django-pagination'  Hi, My... named 'django-pagination' How to remove the ModuleNotFoundError: No module named 'django-pagination' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'dj-pagination'
ModuleNotFoundError: No module named 'dj-pagination'  Hi, My... 'dj-pagination' How to remove the ModuleNotFoundError: No module named 'dj-pagination' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'falcon-pagination'
ModuleNotFoundError: No module named 'falcon-pagination'  Hi, My... named 'falcon-pagination' How to remove the ModuleNotFoundError: No module named 'falcon-pagination' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'filter-and-pagination'
ModuleNotFoundError: No module named 'filter-and-pagination'  Hi...: No module named 'filter-and-pagination' How to remove the ModuleNotFoundError: No module named 'filter-and-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'filter-and-pagination'
ModuleNotFoundError: No module named 'filter-and-pagination'  Hi...: No module named 'filter-and-pagination' How to remove the ModuleNotFoundError: No module named 'filter-and-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'incuna-pagination'
ModuleNotFoundError: No module named 'incuna-pagination'  Hi, My... named 'incuna-pagination' How to remove the ModuleNotFoundError: No module named 'incuna-pagination' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyramid_pagination'
ModuleNotFoundError: No module named 'pyramid_pagination'  Hi, My... named 'pyramid_pagination' How to remove the ModuleNotFoundError: No module named 'pyramid_pagination' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'sqlalchemy-pagination'
ModuleNotFoundError: No module named 'sqlalchemy-pagination'  Hi...: No module named 'sqlalchemy-pagination' How to remove the ModuleNotFoundError: No module named 'sqlalchemy-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'terminal-pagination'
ModuleNotFoundError: No module named 'terminal-pagination'  Hi, My... named 'terminal-pagination' How to remove the ModuleNotFoundError: No module named 'terminal-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'api_pagination'
ModuleNotFoundError: No module named 'api_pagination'  Hi, My... named 'api_pagination' How to remove the ModuleNotFoundError: No module named 'api_pagination' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'apistar-pagination'
ModuleNotFoundError: No module named 'apistar-pagination'  Hi, My... named 'apistar-pagination' How to remove the ModuleNotFoundError: No module named 'apistar-pagination' error? Thanks   Hi, In your

Ads