jsp分页代码有问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 16:13:52
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.io.*,java.sql.*,java.util.*" %>
<html>
<head>
<title>
xianshi
</title>
</head>
<body>
<%!
int pageSize =3;
int pageCount=0;

%>
<%
Connection conn=null;
ResultSet rs;
try{
conn=DriverManager.getConnection("proxool.db");
String sql="select * from tbl_type";
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery(sql);
rs.last();
int rowCount=rs.getRow();
out.println(rowCount +"\n");
pageCount=(rowCount % pageSize==0)? (rowCount/pageSize):(rowCount/pageSize+1) ;

out.println(pageCount);
int showPage=1;
%>
<%
String goToPage=request.g

还是用javaBean比较好,显示与处理分离,明了。
给你一个,通用的,不过要把其对象放到Session中,切记啦
public class Pagination {
private int currentPage; //当前页
private int totalPages; //总页数
private int pageRows; //每页记录数
private int totalRows; //总记录数
private int pageStartRow; //每页开始记录
private int pageEndRow; //每页结束记录
private boolean hasPreviousPage; //是否有上一页
private boolean hasNextPage; //是否有下一页
private List<Object> totalList; //要分页的数据
//初始化页面信息
public void initPage(List<Object> totalList,int pageRows){
this.totalList = totalList;
this.pageRows = pageRows;
this.totalRows = totalList.size();
this.currentPage = 1;
// 计算总页数
if ((totalRows % pageRows) == 0) {
totalPages = totalRows / pageRows;
if (this.totalRows == 0)
this.totalPages = 1;
} else {
totalPages = totalRows / pageRows + 1;
}
// 默认无上一页
this.hasPreviousPage = false;