【转】一个用JSP实现的分页的类及调用方法
代码
l_start = l_curpage * int_num;
l_end = l_start + int_num;
if (l_end > l_totalnum)
l_end = l_totalnum;
l_totalpage = (long)Math.ceil((double)l_totalnum/(double)int_num);
}
//PageCt.Java 分页的类
package vod;
import java.sql.*;
import java.util.*;
public class PageCt
{
private long l_start; //开始纪录
private long l_end; //结束纪录
private long l_curpage; //当前页数
private long l_totalnum;//总记录数
private int int_num=5; //每页10条
private long l_totalpage; //总的页数
public void Init(long currentpage,long totalnum)
{
l_curpage = currentpage;
l_totalnum = totalnum;
if (currentpage>=0)
{
if (currentpage>=(long)Math.ceil((double)l_totalnum/(double)int_num))
l_curpage = (long)Math.floor((double)l_totalnum/(double)int_num);
else
l_curpage = currentpage;
}
else
package vod;
import java.sql.*;
import java.util.*;
public class PageCt
{
private long l_start; //开始纪录
private long l_end; //结束纪录
private long l_curpage; //当前页数
private long l_totalnum;//总记录数
private int int_num=5; //每页10条
private long l_totalpage; //总的页数
public void Init(long currentpage,long totalnum)
{
l_curpage = currentpage;
l_totalnum = totalnum;
if (currentpage>=0)
{
if (currentpage>=(long)Math.ceil((double)l_totalnum/(double)int_num))
l_curpage = (long)Math.floor((double)l_totalnum/(double)int_num);
else
l_curpage = currentpage;
}
else
l_curpage = 0;
l_start = l_curpage * int_num;
l_end = l_start + int_num;
if (l_end > l_totalnum)
l_end = l_totalnum;
l_totalpage = (long)Math.ceil((double)l_totalnum/(double)int_num);
}
public long getCurpage(){
return l_curpage;
return l_curpage;
}
public long getPrepage()
{
if (l_curpage-1>=0)
return l_curpage-1;
else
return 0;
}
{
if (l_curpage-1>=0)
return l_curpage-1;
else
return 0;
}
public long getNextpage()
{
if (l_curpage+1<=l_totalpage)
return l_curpage+1;
else
return l_totalpage;
}
{
if (l_curpage+1<=l_totalpage)
return l_curpage+1;
else
return l_totalpage;
}
public long getTotalnum()
{
return l_totalnum;
}
{
return l_totalnum;
}
public long getTotalpage()
{
return l_totalpage;
}
{
return l_totalpage;
}
public long getStart()
{
return l_start;
}
{
return l_start;
}
public long getEnd()
{
return l_end;
}
};
{
return l_end;
}
};
代码
//调用例子
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*"%>
<%@ page contentType="text/Html;charset=gb2312" %>
<jsp:useBean id="PageCount" scope="page" class="kstest.PageCt" />
<jsp:useBean id="sqlbean" scope="page" class="vod.sql_data" />
<html>
<head></head>
<body>
<table width=600>
<tr bgcolor=#b5dbff>
<form method=GET action=index.jsp>
<td width=80 align=center valign=bottom>共 <%=PageCt.getTotalnum()%> 条</td>
<td width=80 align=center valign=bottom><%=PageCt.getCurpage()+1%>/<%=PageCt.getTotalpage()%> 页</td>
<td width=120 align=center>查看第 <input type=text name=Query_Page size=3> 页</td>
<td width=50 align=center valign=bottom><a href=index.jsp?currentpage=<%=PageCt.getPrepage()%>>上页</a></td>
<td width=50 align=center valign=bottom><a href=index.jsp?currentpage=<%=PageCt.getNextpage()%>>下页</a>
</td>
</tr>
</table>
</body>
</html>
//调用例子
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*"%>
<%@ page contentType="text/Html;charset=gb2312" %>
<jsp:useBean id="PageCount" scope="page" class="kstest.PageCt" />
<jsp:useBean id="sqlbean" scope="page" class="vod.sql_data" />
<html>
<head></head>
<body>
<table width=600>
<tr bgcolor=#b5dbff>
<form method=GET action=index.jsp>
<td width=80 align=center valign=bottom>共 <%=PageCt.getTotalnum()%> 条</td>
<td width=80 align=center valign=bottom><%=PageCt.getCurpage()+1%>/<%=PageCt.getTotalpage()%> 页</td>
<td width=120 align=center>查看第 <input type=text name=Query_Page size=3> 页</td>
<td width=50 align=center valign=bottom><a href=index.jsp?currentpage=<%=PageCt.getPrepage()%>>上页</a></td>
<td width=50 align=center valign=bottom><a href=index.jsp?currentpage=<%=PageCt.getNextpage()%>>下页</a>
</td>
</tr>
</table>
</body>
</html>