日期:2014-05-18  浏览次数:21042 次

50分求个通用的分页代码,帮顶的也有分,:)谢谢了
郁闷啊,写了老多,结果一提交,该页无法显示,后退,东西没有,
TNND!:(

还是关于分页技术,老实现不了,结果搞来搞去,还是在页面里面嵌代码来实现,实在是让人郁闷,搞了下,试着让他分离出来,结果总搞不定,貌似思路一直都有问题。
求一个,看看大大们怎么实现的,
希望能通用那种,最好用标签实现,然后能定义每页显示多少多少条,

50分给最终能完美解决的朋友,剩下的分给帮顶的朋友,不够的话再加,
先谢了.

PS:这次要是提交再无法显示的话,我就XX   CSDN!-   -#,还是先copy一下吧,保险点.

------解决方案--------------------
<%@ page language= "java " import= "java.lang.* " pageEncoding= "gb2312 "%>
<%!int rowsPerPage=15; %>
<%@ include file= "connect.jsp " %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+ ":// "+request.getServerName()

+ ": "+request.getServerPort()+path+ "/ ";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<base href= " <%=basePath%> ">
<title> 数据库连接 </title>
<meta http-equiv= "pragma " content= "no-cache ">
<meta http-equiv= "cache-control " content= "no-cache ">
<meta http-equiv= "expires " content= "0 ">
<meta http-equiv= "keywords "

content= "keyword1,keyword2,keyword3 ">
<meta http-equiv= "description " content= "This is my page ">
<!--
<link rel= "stylesheet " type= "text/css " href= "styles.css ">
-->
</head>
<body>
<table border= "1 " bgcolor= "#00ff00 " align= "center " name= "table ">

<%
int currentPage=1;
try
{
stmt=con.createStatement

(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql= "select * from course order by course_no desc ";
rs=stmt.executeQuery(sql);
if(rs!=null)
{
rs.last();
int maxRows=rs.getRow();//总共行数

//总页数
int pageCount=(maxRows/rowsPerPage==0)?maxRows/rowsPerPage:

(maxRows/rowsPerPage+1);
String strCurPage=request.getParameter( "curPage ");
if(strCurPage==null)
currentPage=1;
else
{
currentPage=Integer.parseInt(strCurPage);
}
if(currentPage> pageCount)
currentPage=pageCount;
if(currentPage <1)
currentPage=1;
int position=(currentPage-1)*rowsPerPage+1;//光标移动到当前页的第一


rs.absolute(position);
%>
<tr>
<td> 课程编号 </td>
<td> 课程名 </td>
<td> 学分 </td>
<td> 教师编号 </td>
<td> 删除 </td>
</tr>
<%

for(int i=0;i <rowsPerPage;i++)
{
String name=rs.getString( "course_no ");
if(rs.getRow()> maxRows) break;
%>
<tr>
<td> <%=rs.getString(1) %> </td>
<td> <%=rs.getString(2) %> </td>
<td> <%=rs.getString(3) %> </td>
<td> <%=rs.getString(4) %> </td>
<td> <a href= "delete.jsp?name= <%=name %> "> 删除 </a> </td>
</tr>