Pagination in jsp.
<%@include file="header.jsp" %>
<style>
#listings
{
display:block;
height:30px;
margin:0;
padding:0;
text-align:center;
color: white; background-color: green;
display:inline-block;
line-height:25px;
list-style:none;
margin-right:1px;
padding:0;
text-align:center;
width:30px;
text-decoration:none;
margin-left:2px;
font-size:15px;
}
#testing
{
font-size:15px;
color:black;
}
</style>
<%
int page1;
if (request.getSession(false) == null) {
response.sendRedirect("index.jsp");
}
user.Methods m=new user.Methods();
String mail=session.getAttribute("email").toString();
String pass=session.getAttribute("pass").toString();
%>
<table>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<table align="center" cellspacing="0" cellpadding="0" style="width:1000px; margin-left: 180px;">
<tr style="background-color:green;height:40px;">
<th style="text-align: left;color:white;">Active Ads(<%=m.adswithphoto()%>)</th><th style="text-align: left;color:white;">Expired Ads(<%=m.expiread()%>)</th><th style="text-align: left;color:white;" colspan="2">Pending Ads</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<%
if(!request.getParameter("page").equals(""))
{
page1 = Integer.parseInt(request.getParameter("page"));
}
else
{
page1=1;
}
//System.out.print("page1-"+page1);
// System.out.print(mail);
int start_from = (page1-1)*5;
//System.out.print(start_from);
try{
databse db1=new databse();
Connection con1=db1.connectit();
String sql23="select * from posts where status='Active' and mailid='"+mail+"' limit "+start_from+" , 5";
PreparedStatement pste=con1.prepareStatement(sql23);
ResultSet rs3=pste.executeQuery();
while(rs3.next())
{
%>
<tr>
<td><a href="postdetails.jsp?postid=<%=rs3.getString(1)%>"><img src="${pageContext.request.contextPath}/upload/<%=rs3.getString(12)%>" width='100px' height='100px' style="border-radius: 5px;"/></a></td>
<td><%=rs3.getString("adtitle")%>
</br>
<span style="font-size: 8px;"><a href="postdetails.jsp?postid=<%=rs3.getString(1)%>">Buy n Sell > <%=rs3.getString(2)%> > <%=rs3.getString(3)%></a></span>
</br>
<span style="font-size: 8px;"><a href="postdetails.jsp?postid=<%=rs3.getString(1)%>"><%=rs3.getString("address")%></a></span>
</td>
<td>
<a href="postdetails.jsp?postid=<%=rs3.getString(1)%>">
Rs <%=rs3.getString("price")%> <%=rs3.getString("date")%>
</a>
<td>
<a href="editpost.jsp?postid=<%=rs3.getInt(1)%>"><img src="images/load.png" height="40" width="30"></a>
<a href="deletepost.jsp?postid=<%=rs3.getInt(1)%>"><img src="images/delete.png" height="40" width="30"></a>
</td>
</td>
</tr>
<%
}}catch(Exception e){}
%>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<div style="margin-left: 520px;">
<%
int tt=0;
try
{
databse jj=new databse();
Connection kk=jj.connectit();
PreparedStatement pstee=kk.prepareStatement("SELECT COUNT(id) FROM posts");
ResultSet rd=pstee.executeQuery();
while(rd.next())
{
tt+=rd.getInt(1);
}
int total_pages = (int)Math.abs(tt / 2);
page1 = 1;
if(!request.getParameter("page").equals(""))
page1 = Integer.parseInt(request.getParameter("page"));
int prev = page1 - 1;
%>
<a href='allpost.jsp?page=1' id='testing'>First</a>
<%
if(prev >= 1)
%>
<a href='allpost.jsp?page=<%=prev%>' id='testing'>Prev</a>
<%
for (int i = 1; i <= tt; i++)
{
if(tt != 1)
{
%>
<a href='allpost.jsp?page=<%=i%>' id='listings'><%=i%></a>
<%
}
}
int next = page1 + 1;
System.out.println("next"+next);
System.out.println("tp"+total_pages);
if(next <= total_pages)
%>
<a href="allpost.jsp?page=<%=next%>" id="testing">Next</a>
<a href="allpost.jsp?page=<%=total_pages%>" id="testing">Last</a>
<%
}
catch(Exception e)
{
}
%>
</div>
<%@include file="footer.jsp" %>