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 or attribute directive in tag file, attribute items does not accept any expressions
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.
Ads
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
Advertisements
How to connect to MySQL in JSP?
How to connect to MySQL in
JSP?
How to connect to MySQL in
JSP...,
You
can use the Java JDBC code to connect to MySQL database in
JSP page. Check the tutorial:
Connect
JSP with mysql
Thanks
How to use ajax in jsp?
How to use ajax in
jsp? Hi,
How i
can access the server-side data in
JSP using the Ajax?
Thanks
Hi,
You
can use the Ajax code to access the server side data from
JSP page.
Check the tutorial Combo Box Using Ajax
How to break statement in JSP
How to break statement in JSP Hi,
I am writing
JSP page and there is for loop inside it.
How to break statement in
JSP?
Thanks
Hi,
I
JSP you
can use the break statement to break a loop.
Here is simple example
How to break statement in JSP
How to break statement in JSP Hi,
I am writing
JSP page and there is for loop inside it.
How to break statement in
JSP?
Thanks
Hi,
I
JSP you
can use the break statement to break a loop.
Here is simple example
How to break statement in JSP
How to break statement in JSP Hi,
I am writing
JSP page and there is for loop inside it.
How to break statement in
JSP?
Thanks
Hi,
I
JSP you
can use the break statement to break a loop.
Here is simple example
How to break statement in JSP
How to break statement in JSP Hi,
I am writing
JSP page and there is for loop inside it.
How to break statement in
JSP?
Thanks
Hi,
I
JSP you
can use the break statement to break a loop.
Here is simple example
How to Open JSP?
How to Open
JSP?
In this section you learn
How to Open
JSP in text editor. The
JSP... will open
the
JSP file in the editor window. In the editor window you
can easily edit
How to compile and run the JSP
How to compile and run the JSP Hi
Kindly tell me
how to run and compile
JSP small Program using Tomcat as webserver.
I created small program HELLO
JSP in HTML and compile the program but it is saying Class o r interface
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
How to make first JSP page?
How to make first
JSP page? Hello,
How I
can make first
JSP page?
Thanks
HI,
Beginner
can learn
JSP from writing the first Program. You
can do it manually by creating a web application and then write
jsp page
How to access the database from JSP?
How to access the database from
JSP? Hi,
What is the process of accessing the database from
JSP page?
Thanks
Hi,
In the
JSP program... database from
JSP which explains you
how to access the database by embedding
How to save value in JSP
324 2012-12-12
save
i want to save dis value
jsp to action ...
how can i get all value ..and store..
how can its values goes...
How to save value in JSP Employee Name Time-IN Time-OUT
how to convert jsp to exe
how to convert
jsp to exe hello sir,
i am doing webapplication. the configuration is windows xp operating system,IE6.0,apache tomcat5.0,j2se5.0 and
jsp,servlets i am using.this is doing in localhost only. now i want
how call ireports in jsp
how call ireports in jsp please send me code any one for calling ireports in servlet-
jsp program i am trying to call the ireports in servlet and
jsp error is occurred
exception:
javax.servlet.ServletException
How to use contentType Attribute in JSP?
How to use contentType Attribute in
JSP? Hi,
I am learning
JSP and now trying to use the contentType Attribute in
JSP. tell me
how to use the contentType Attribute in
JSP?
Thanks
How To Include Two Jsp page in another jsp page?
How To Include Two
Jsp page in another
jsp page? I use following code to Include Two
Jsp Page Header and footer
<%@include file="header.jsp... in page
How can i Display at correct position?
Please visit