45fan.com - 路饭网

搜索: 您的位置主页 > 电脑频道 > 电脑教程 > 阅读资讯:jsp分页的方法

jsp分页的方法

2016-09-01 07:55:19 来源:www.45fan.com 【

jsp分页的方法

**************************************************
InberGong 10:24 2003-12-16
**************************************************
jsp运行环境:
windows2000+tomcat-4.1.24+j2sdk-1_4_1_01-windows-i586+jdbcforsql2000+sql2000
**************************************
1配置Tomcat 4.1/webapps/examples/WEB-INF中的web.xml加入
**************************************
<taglib>
<taglib-uri>http://xiaolie.vicp.net/divpage-taglib</taglib-uri>
<taglib-location>/WEB-INF/divpage-taglib.tld</taglib-location>
</taglib>
*************************************
2新建一个文件命名为:divpage-taglib.tld将些文件放在WEB-INF目录下.
内容为:
*********************************************
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>page list</short-name>
<!--<uri>http://jakarta.apache.org/tomcat/kbq-taglib</uri>-->
<uri>http://xiaolie.vicp.net/kbq-taglib</uri>
<description>
A tab library for list pages
</description>


<!-- a set of pages roller tag -->
<tag>
<name>pages_roller</name>
<tag-class>com.xiaolie.tag.pages.PagesRollerTag</tag-class>
<tei-class>com.xiaolie.tag.pages.PagesRollerExtraInfo</tei-class>
<description>
if have next page to show a content of link to next page.
this rag is write after list and must have a attribute "sumPages"
</description>
<attribute>
<name>sumPages</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<tag>
<name>first_page</name>
<tag-class>com.xiaolie.tag.pages.FirstPageTag</tag-class>
<description>
if current page is not first page to show a content of link to first page.
</description>
</tag>

<tag>
<name>next_page</name>
<tag-class>com.xiaolie.tag.pages.NextPageTag</tag-class>
<!--<tei-class>com.xiaolie.tag.pages.NextPageExtraInfo</tei-class>-->
<description>
if have next page to show a content of link to next page.
</description>
</tag>

<tag>
<name>prev_page</name>
<tag-class>com.xiaolie.tag.pages.PrevPageTag</tag-class>
<description>
if have prev page to show a content of link to next page.
</description>
</tag>

<tag>
<name>last_page</name>
<tag-class>com.xiaolie.tag.pages.LastPageTag</tag-class>
<description>
if current page is not last page to show a content of link to first page.
</description>
</tag>

<tag>
<name>list_control</name>
<tag-class>com.xiaolie.tag.pages.ListControlTag</tag-class>
<tei-class>com.xiaolie.tag.pages.ListControlExtraInfo</tei-class>
<description>
It contain sub tag: list_prev_tag,list_page,list_next_tag.
You can set Max list number attribute here.
</description>
<attribute>
<name>maxNum</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<tag>
<name>list_prev_pages</name>
<tag-class>com.xiaolie.tag.pages.ListPrevPageTag</tag-class>
<!--<tei-class>com.xiaolie.tag.pages.ListPrevPageExtraInfo</tei-class>-->
<description>
show a prev 10 pages list.
</description>
</tag>

<tag>
<name>list_pages</name>
<tag-class>com.xiaolie.tag.pages.ListPageTag</tag-class>
<tei-class>com.xiaolie.tag.pages.ListPageExtraInfo</tei-class>
<description>
show a page list.
</description>
</tag>

<tag>
<name>list_next_pages</name>
<tag-class>com.xiaolie.tag.pages.ListNextPageTag</tag-class>
<!--<tei-class>com.xiaolie.tag.pages.ListNextPageExtraInfo</tei-class>-->
<description>
show a next 10 pages list.
</description>
</tag>

</taglib>
*******************************************
3使用方法:
有页面头部加上
<%@ taglib uri="http://xiaolie.vicp.net/divpage-taglib" prefix="dp"%>
以下是在一个表格中的分页代码:
**************************************************************
<table width="92%" border="0" cellspacing="0" align="center">
<tr>
<td valign="top"> <table width="100%" border="0" cellspacing="1" align="center" bgcolor="#E4E4E4" cellpadding="3">
<tr bgcolor="#eeeeee">
<td class="word">&nbsp; </td>
<%
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
int intPageSize; //一页显示的记录数
intPageSize = 5;
//out.close();
String sql = "select * from reged_user";
ResultSet rs=stmt.executeQuery(sql);
//将指针移到最后
rs.last();
//统计页数
intRowCount = rs.getRow();
//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//out.close();
%><dp:pages_roller sumPages='<%=intPageCount%>'>
<%
if(intPageCount>0){
int tmpNum = 1;
//将记录指针定位到待显示页的第一条记录上
int intCpage=java.lang.Integer.parseInt(pageno);
rs.absolute((intCpage-1) * intPageSize + 1);
//显示数据
int i = 0;
String tmpId,tmpContent,tmpTitle,tmpDates;
%>
<td width="51%" class="word"><div align="right">共<%=intRowCount%>条纪录,目前<%=intCpage%>/<%=intPageCount%>页</div></td>
</tr>
<%

while(i<intPageSize && !rs.isAfterLast()){
//获取各个字段的值
tmpId=rs.getString("id");
tmpTitle=rs.getString("easy_name");
tmpContent=rs.getString("user_name");
%>
<tr bgcolor="#FFFFFF">
<td width="38%" class="word"><%=tmpTitle%></td>
<td width="11%" class="word"><font face="Arial, Helvetica, sans-serif"><a href="http://<%=tmpContent%>" target="_blank"><%=tmpContent%></a></font></td>

</tr>
<%
tmpNum++;
rs.next();
i++;
}
}
%>
</table>
<p>&nbsp;</p></td>
</tr>
<tr>
<td height="43" valign="top"><div align="center">
<table width=148 border=0 align="right" cellpadding=0 cellspacing=0>
<tr>
<td width="42" height="33"> <a href="<%=firsturl%>"><img src="images/biao_01.gif" width=36 height=33 alt="" border="0"></a></td>
<td width="41"> <a href="<%=prevurl%>"><img src="images/biao_02.gif" width=35 height=33 alt="前<%=intPageSize%>条纪录" border="0"></a></td>
<td width="33"> <a href="<%=nexturl%>"><img src="images/biao_03.gif" width=28 height=33 alt="后<%=intPageSize%>条纪录" border="0"></a></td>
<td width="32"> <a href="<%=lasturl%>"><img src="images/biao_04.gif" width=32 height=33 alt="" border="0"></a></td>
</tr>
</table>
</div></td>
</tr></dp:pages_roller>
</table>
**************************************************************

 

本文地址:http://www.45fan.com/dnjc/70615.html
Tags: JSP InberGong 2003-12-16
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部