jsp实现分页技术
2006-05-01 14:11
525 查看
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.sql.*,com.applestudio.util.*"%>
<%@ page errorPage="error.jsp"%>
<%
request.setCharacterEncoding("GBK");
int PageSize= 5;
int RecordNum=0;
int PageNum=1;
int CurrentPage;
int CurrentIndex;
String strPage = request.getParameter("page");
if(strPage==null){
CurrentPage = 1;
}else{
CurrentPage = Integer.parseInt(strPage);
if(CurrentPage<1) CurrentPage = 1;
}
OperationDB odb=new OperationDB();
String sql;
ResultSet rs;
%>
<html>
<head>
<title>测试分页</title>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<table width="98%" border="0" cellpadding="0" cellspacing="0" height="151">
<%
sql="select * from sutdent";
rs=odb.executeQuery(sql);
if(!rs.last()){
out.println("<tr><td align=center height=25>无数据.</td></tr>");
}else{
RecordNum = rs.getRow();
PageNum = (RecordNum+PageSize-1) / PageSize;
if(CurrentPage>PageNum) CurrentPage = PageNum;
if(PageNum>0){
CurrentIndex=(CurrentPage-1) * PageSize + 1;
rs.absolute(CurrentIndex);
int endRow=CurrentIndex+PageSize;
while(!rs.isAfterLast()&&rs.getRow()!=endRow){
%>
<tr>
<td bgcolor="#dddddd" height="25"><b><%=rs.getString("name")%></b></td>
</tr>
<%
rs.next();
}
}
rs.close();
}
%>
<tr>
<td width="78%" style="padding:0;" align="right" height="8">
<%if(CurrentPage>1){%>
<a href="?page=1">第一页</a>
<a href="?page=<%=CurrentPage-1%>">上一页</a>
<%}else{%>
<font class="stext">第一页 上一页 </font>
<%}if(CurrentPage<PageNum){%>
<a href="?page=<%=CurrentPage+1%>">下一页</a>
<a href="?page=<%=PageNum%>">第末页</a>
<%}else{%>
<font class="stext">下一页 第末页</font>
<%}%> 转到第<select onchange="window.location='?page='+this.value" name="gopage">
<%for(int i=1;i<=PageNum;i++){%>
<option <%if(i==CurrentPage){%>selected<%}%> value="<%=i%>"><%=i%></option>
<%}%></select>页
</td>
</table>
</body>
</html>
<%@ page import="java.sql.*,com.applestudio.util.*"%>
<%@ page errorPage="error.jsp"%>
<%
request.setCharacterEncoding("GBK");
int PageSize= 5;
int RecordNum=0;
int PageNum=1;
int CurrentPage;
int CurrentIndex;
String strPage = request.getParameter("page");
if(strPage==null){
CurrentPage = 1;
}else{
CurrentPage = Integer.parseInt(strPage);
if(CurrentPage<1) CurrentPage = 1;
}
OperationDB odb=new OperationDB();
String sql;
ResultSet rs;
%>
<html>
<head>
<title>测试分页</title>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<table width="98%" border="0" cellpadding="0" cellspacing="0" height="151">
<%
sql="select * from sutdent";
rs=odb.executeQuery(sql);
if(!rs.last()){
out.println("<tr><td align=center height=25>无数据.</td></tr>");
}else{
RecordNum = rs.getRow();
PageNum = (RecordNum+PageSize-1) / PageSize;
if(CurrentPage>PageNum) CurrentPage = PageNum;
if(PageNum>0){
CurrentIndex=(CurrentPage-1) * PageSize + 1;
rs.absolute(CurrentIndex);
int endRow=CurrentIndex+PageSize;
while(!rs.isAfterLast()&&rs.getRow()!=endRow){
%>
<tr>
<td bgcolor="#dddddd" height="25"><b><%=rs.getString("name")%></b></td>
</tr>
<%
rs.next();
}
}
rs.close();
}
%>
<tr>
<td width="78%" style="padding:0;" align="right" height="8">
<%if(CurrentPage>1){%>
<a href="?page=1">第一页</a>
<a href="?page=<%=CurrentPage-1%>">上一页</a>
<%}else{%>
<font class="stext">第一页 上一页 </font>
<%}if(CurrentPage<PageNum){%>
<a href="?page=<%=CurrentPage+1%>">下一页</a>
<a href="?page=<%=PageNum%>">第末页</a>
<%}else{%>
<font class="stext">下一页 第末页</font>
<%}%> 转到第<select onchange="window.location='?page='+this.value" name="gopage">
<%for(int i=1;i<=PageNum;i++){%>
<option <%if(i==CurrentPage){%>selected<%}%> value="<%=i%>"><%=i%></option>
<%}%></select>页
</td>
</table>
</body>
</html>
相关文章推荐
- JSP分页技术实现
- JSP分页技术实现[转]
- JSP分页技术实现
- jsp读取数据库实现分页技术简析
- JSP分页技术实现
- 利用ajax技术实现通用分页,在jsp页面呈现
- 说下jsp分页技术是怎么样实现的???
- JSP分页技术实现
- JSP分页技术实现 使用工具类实现通用分页处理
- jsp分页技术的例子实现和总结
- JSP分页技术实现[转]
- JSP分页技术实现 (附代码)
- JSP分页技术实现
- jsp分页技术的实现
- JSP分页技术实现
- JSP分页技术实现
- JSP分页技术实现
- JSP学习之------>JSP分页技术实现 [转贴]
- JSP分页技术实现
- JAVA_WEB项目(结合Servlet+jsp+ckEditor编辑器+jquery easyui技术)实现新闻发布管理系统第四篇:前台首页,新闻分类(体育新闻,科技新闻等),新闻列表分页的实现