日期:2014-05-17  浏览次数:20757 次

jsp的分页问题
不用分页可以显示数据,一用就不能显示了


<%@ page language="java" import="java.util.*,java.sql.*"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
//session判断登陆
request.setCharacterEncoding("utf-8");
if (session.getAttribute("name") == null) {
response.setHeader("Refresh", "0;URL=Login.jsp");
} else {
}
//分页代码
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/storagemanage?user=root&password=123&useUnicode=true&characterEncoding=utf-8";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select contentwarehouse.CW_ID,typecontrol.TC_TypeName,contentwarehouse.CW_Goods,contentwarehouse.CW_ContentOfGoods,contentwarehouse.CW_Content "
+ "from contentwarehouse INNER JOIN typecontrol ON contentwarehouse.TC_ID=typecontrol.TC_ID";
ResultSet rs = stmt.executeQuery(sql);
int intPageSize; //一页显示的记录数    
int intRowCount; //记录总数    
int intPageCount; //总页数    
int intPage; //待显示页码  
int i;
String strPage;

intPageSize = 8;//设置一页显示的记录数   
i = 0;//取得待显示页码   
strPage = request.getParameter("page");
if (strPage == null) {
intPage = 1;
} else {
intPage = Integer.parseInt(strPage);
if (intPage < 1)
intPage = 1;
}
rs.last();
intRowCount = rs.getRow();//获取记录数
intPageCount = (intRowCount + intPageSize - 1) / intPageSize;//记算总页数
if (intPage > intPageCount) {
intPage = intPageCount;
}//调整待显示的页码
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Particulars</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>
<div style="position: relative;top:20%;" align="center">
<table align="center">
<tr>
<th>物品名称</th>
<th>类别</th>
<th>详解</th>
<th>备注</th>
<th>操作</th>
</tr>

<%
if (intPageCount > 0) {

rs.absolute((intPage - 1) * intPageSize + 1);//将记录指针定位到待显示页的第一条记录上    
i = 0;//显示数据
while (i < intPage