Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet how can manages recordset in jsp
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ankit Dweivedi
how can manages recordset in jsp
2 Answer(s)      3 years and 8 months ago
Posted in : JSP-Servlet


I am ask a question how can show 5-5 records in jsp page and I get answer provided by you but it give exception:-

org.apache.jasper.JasperException: /jsp/paging.jsp(75,0) According to TLD or attribute directive in tag file, attribute items does not accept any expressions


Advertisement
View Answers

April 18, 2011 at 5:47 PM


pagination.jsp:

<%@ 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=5;
int totalRecords=5;
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 employee 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>
<th>Name</th><th>Address</th><th>Contact</th><th>Email</th>
</tr>
<%
while(rs1.next()){
%>
<tr><td><%=rs1.getString("name")%></td><td><%=rs1.getString("address")%></td><td><%=rs1.getInt("contactNo")%></td>
<td><%=rs1.getString("email")%></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>
<%
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>


March 31, 2013 at 3:32 PM


I have a question that you are using SQL but in case of oracle database how can i solve this. I don't want to use tag library. I want to handle it locally.



Related Tutorials/Questions & Answers:
how can manages recordset in jsp
how can manages recordset in jsp  I am ask a question how can show 5-5 records in jsp page and I get answer provided by you but it give exception:- org.apache.jasper.JasperException: /jsp/paging.jsp(75,0) According to TLD
how can manages records in jsp
how can manages records in jsp  how can sho only five record at a time and next 5 on click next button and so on in jsp
Advertisements
How can i pass the valus from a JSP to the action class???
How can i pass the valus from a JSP to the action class???  hewllo wevryone... can anyone help me with how i can pass the value of menuId in my JSP and pass it in the action class
how can we pass parameters from jsp href to another servlet
how can we pass parameters from jsp href to another servlet  how can we pass parameters from jsp href to another servlet
How i can send mail by using jsp.............. - JavaMail
How i can send mail by using JSP  Hi, will you please tell me how i can send mail by using jsp. Tell me in detail. Thanks!  Example and JSP Code for sending mailSee the give link for JSP coding, that will allow you
How Can I get ArrayList of Data from jsp with ajax request
How Can I get ArrayList of Data from jsp with ajax request  Hi, I retereved 5 Employee Record of Data from Struts Action class to jsp with ajax response. But I don't how how can reterve this dynamic 5 employee records
How can I get the full URL with the attached parameters? - JSP-Servlet
How can I get the full URL with the attached parameters?  Hi, I'm trying to figure out how to get the current url and use it in my jsp page. I...:8080/MesEduSchoolsProject/displayMenu.jsp How can I get the full URL with the attached parameters
how can i connected jsp wih mysql - Java Beginners
how can i connected jsp wih mysql  i have a code jsp file... not exist i have a tomcat 4.0,mysql 5.0, and jdk 1.4 plz any one help me how to connect this and how can i use it plz help me its very urgent plz send my
How can i implement the calculator programe in jsp code
How can i implement the calculator programe in jsp code  Please send code for the calculator using jsp technologies please guidelines to me.   Here is a simple jsp calculator code that accepts two numbers from the user
how i can add an horizontal scrollbar at my PdfAnnotation ? - JSP-Servlet
how i can add an horizontal scrollbar at my PdfAnnotation ?  How to add the an horizontal scrollbar at my PdfAnnotation ? for example document d=new document(0. document.open
User Registration Form Using JSP(JspBeans) after that how i can insert in database
User Registration Form Using JSP(JspBeans) after that how i can insert in database   User Registration Form Using JSP(JspBeans) after that how i can insert in database
how can i send a mail to a particular user from a many user dropdown list in jsp
how can i send a mail to a particular user from a many user dropdown list in jsp  how can i a sent a user question to a particular person from a drop down list in jsp
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.  I am using postgresql-8.4.4-1... netbeans-6.1-ml-windows.How can I set up connection to database? Please help me
how can i use one dbase conection in serveral pages - JSP-Servlet
how can i use one dbase conection in serveral pages  Hi! Thanks for sending code... But my actual requirement is In my project i am writing dbase connections many times whereever i need in several pages. How can I avoid
how should i can solve
how should i can solve  Web based program - Input - Person's contact details with Passport Number as Unique Key. Save data in to oracle / MySQL. Output - List of Persons saved in the database. Technology to be used - JSP
can we write a method in JSP - JSP-Servlet
that second jsp file to avoid code rewriting. how can I do this please help me out... to call another second jsp file. I can do it by redirecting my first jsp file... for execution) of first jsp file by redirecting second page to the first page. I can call
How can we destroy the cookie?
How can we destroy the cookie?   How can we destroy the cookie
How can I do it? .click();
How can I do it? .click();  I have a very unusual problem. I want to make a script like this: <script> x = document.getElementById... want that it make mouseup in this element. How can I do it, because if I write
How can I learn Java?
How can I learn Java?  Hi, I have just completed a course in HTML... programming. How can I learn Java? in shortest possible time. I mean I just want to begin... are the best ways to learn Java for a beginner? Thanks   Hi, You can
How can print integer in method
How can print integer in method   a method call process public process(int jobid,int remain){ } how to print int jobid ,int remain in for loop jobid in proc[0],remain in proc[1],both show in text file how to print proc[0
after entering details in reg page,n enter the submit button,how can v store the data in db, n hw can v retrive the data frm db in jsp
after entering details in reg page,n enter the submit button,how can v store the data in db, n hw can v retrive the data frm db in jsp  i ve creted... the submit button,how can v store the data in db, n hw can v retrive the data frm
How Jdbc program can be run??
How Jdbc program can be run??  import java.sql.*; import java.util.*; class MyDbCode3 { public static void main(String [] args) { try... to know what is the problem? and how can i run it successfully? please give me
How can combine threads and buttons?
How can combine threads and buttons?  I would like to start an application, stop it and restart it again and stop etc. I tried the following code. It does start and stop, but I get an error when I try to restart. Any
Can not find "org.apache.poi " - JSP-Servlet
Can not find "org.apache.poi "  Hi friend, Thanks... an error message that "org.apache.poi " can not be resolved. I have search it form net but i m unable to download the jar file. So can u help me to do
how can i create a discussion forum?
how can i create a discussion forum?  how can i create a discussion forum for my e- mentoring site for women which can be used by a registered user only. i am using jsp and servlets and i am working with netbeans 6.8.
how can we store the encrypted passwaord in swings?
how can we store the encrypted passwaord in swings?   how can we store the encrypted passwaord in swings
how i can get jqfade.js library
how i can get jqfade.js library  how i can get jqfade.j script library
how can download mobile explorer emulator
how can download mobile explorer emulator  how can download mobile explorer emulator
how can i add hibernate plugin to eclipse?
how can i add hibernate plugin to eclipse?  how can i add hibernate plugin to eclipse
How we can create a table through procedure ?
How we can create a table through procedure ?  How we can create a table through procedure
How can we know that a session is started or not?
How can we know that a session is started or not?  How can we know that a session is started
Advertisements
 

 

 

DMCA.com