DAO操作类:
  package com.batian.daoimpl;import java.sql.*;
import java.util.*;import com.batian.common.DBConnection;
import com.batian.dao.InnovationDAO;
import com.batian.vo.*;public class InnovationDAOImpl implements InnovationDAO {    //查询出全部的记录数
public int getCount() {
int allRecorders = 0;
DBConnection conn = null;
conn = new DBConnection();
PreparedStatement psmt = null;
ResultSet rs = null;
String sql = "select count(ID) from hrmt_innovation";
try {
psmt = conn.getConnection().prepareStatement(sql);
rs = psmt.executeQuery();
while(rs.next()){
allRecorders = rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return allRecorders;
}// 查询出全部记录
public List QueryList() {

List list = new ArrayList();
InnovationVO ivo = null;
DBConnection dbc = null;
dbc = new DBConnection();
PreparedStatement psmt = null;
ResultSet rs = null;
String sql = "select * from hrmt_innovation";
//String sql = "select ID,INNOVATION_ID,INNOVATION_DAT,INNOVATION_ITEM,ORG_ID,INNOVATION_DATA from hrmt_innovation ";

try {
psmt = dbc.getConnection().prepareStatement(sql);
System.out.println("queryList conn:"+dbc.getConnection());
rs = psmt.executeQuery();
while(rs.next()){
ivo = new InnovationVO();
ivo.setID(rs.getInt(1));
ivo.setINNOVATION_ID(rs.getString(2));
ivo.setINNOVATION_DAT(rs.getDate(3));
ivo.setINNOVATION_ITEM(rs.getString(4));
ivo.setORG_ID(rs.getString(5));
ivo.setINNOVATION_DATA(rs.getString(6));
list.add(ivo);
//System.out.println("java's size():"+list.size());
}
rs.close();
psmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
dbc.close();
}
return list;
} public static void main(String [] args){
System.out.println("size :"+new InnovationDAOImpl().getCount());
System.out.println("main conn:"+new InnovationDAOImpl());
}
}jsp 代码:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,com.batian.factory.*,java.util.*,com.batian.vo.*"%>
<html>
<head>
<title>分页显示</title>
</head>
<body>
<center>
<h1>
Innvoation 信息列表
</h1>
<hr>
<br>
<%!final String jspUrl = "list_innovation_page.jsp";%>
<%
int lineSize = 10;
int currentPage = 1;
int pageSize = 0;
int allRecorders = 30;
%>
<%
try {
currentPage = Integer.parseInt(request.getParameter("cp"));
} catch (Exception e) {
}
%>
<%
allRecorders = DAOFactory.getInnovationDAOInstance().getCount(); pageSize = (allRecorders + lineSize - 1) / lineSize; List list = DAOFactory.getInnovationDAOInstance().QueryList();
System.out.println("size's:"+list.size()+"pagesize:"+pageSize);
%>
<script language="javaScript">
function openPage(curpage)
{
document.spage.cp.value = curpage ;
    //alert(cupage) ;
document.spage.submit() ;
}
function selOpenPage()
{
document.spage.cp.value = document.spage.selpage.value ;
document.spage.submit() ;
}
</script>
<form name="spage" action="<%=jspUrl%>">
<input type="button" value="首页" onClick="openPage(1)"
<%=currentPage == 1 ? "disabled" : ""%>>
<input type="button" value="上一页"
onClick="openPage(<%=currentPage - 1%>)"
<%=currentPage == 1 ? "disabled" : ""%>>
<input type="button" value="下一页"
onClick="openPage(<%=currentPage + 1%>)"
<%=currentPage == pageSize ? "disabled" : ""%>>
<input type="button" value="尾页" onClick="openPage(<%=pageSize%>)"
<%=currentPage == pageSize ? "disabled" : ""%>>
<input type="hidden" name="cp" value="">
<font color="red" size="5"><%=currentPage%>
</font> /
<font color="red" size="5"><%=pageSize%>
</font> 跳转到
<select name="selpage" onChange="selOpenPage()">
<%
for (int x = 1; x <= pageSize; x++) {
%>
<option value="<%=x%>" <%=currentPage == x ? "selected" : ""%>>
<%=x%>
</option>
<%
}
%>
</select>

</form>
<table border="1" width="80%">
<tr>
<th>ID</th>
<th>INNO_ID</th>
<th>INNO_DAT</th>
<th>INNO_ITEM</th>
<th>ORG_ID</th>
<th>INNO_DATA</th>
<th>NEXT_INNOVATION_ITEM</th>
<th>NEXT_INNOVATION_DATA</th>
<th>CURRENT_GRADE</th>
<th>CURRENT_ORDER</th>
<th>ACCUMULATIVE_GRADE</th>
<th>REMARK</th>
</tr>
<%
int i = 0;
Iterator iter = list.iterator();
for (int x = 0; x < (currentPage - 1) * lineSize; x++) {
iter.hasNext();
}
// 对于输出代码之前要求按显示的页数空出
for (int x = 0; x < lineSize; x++) {
if (iter.hasNext()) {
i++;
InnovationVO ivo = (InnovationVO)iter.next();
int id = ivo.getID();
String innovate_ID = ivo.getINNOVATION_ID();
java.sql.Date innovate_Date = ivo.getINNOVATION_DAT();
String innovate_Item = ivo.getNEXT_INNOVATION_ITEM();
String org_ID = ivo.getORG_ID();
String innovate_Data = ivo.getINNOVATION_DATA();
String innovationItem = ivo.getNEXT_INNOVATION_ITEM();
String innovationData = ivo.getNEXT_INNOVATION_DATA();
int currentGrade = ivo.getCURRENT_GRADE();
int currentOrder = ivo.getCURRENT_ORDER();
String re = ivo.getREMARK();
%>
<tr>
<td><%=id%></td>
<td><%=innovate_ID%></td>
<td><%=innovate_Date%></td>
<td><%=innovate_Item%></td>
<td><%=org_ID%></td>
<td><%=innovate_Data%></td>
<td><%=innovate_Data%></td>
<td><%=innovationItem%></td>
<td><%=innovationData%></td>
<td><%=currentGrade%></td>
<td><%=currentOrder%></td>
<td><%=re%></td>
</tr>
<%
}
}
if (i == 0) {
%>
<tr>
<td colspan="6">
没有任何数据!!
</td>
</tr>
<%
}
%>
</table>
<%
} catch (Exception e) {
%>
<h2>
系统出错!!!
</h2>
</center>
</body>
</html>出现的结果就是:在点点击上一页,下在页的时候:页面会跳动,可该页面的数据不会变:我认为是两个for循环中的语句所造成的!