jsp下的几种分页

totalPages总页数,pageNO第几页,ShowArticleFlat.jsp为你要提交页面
ResultSet rsCount = stmt.executeQuery("select count(*) from article where pid = 0");
rsCount.next();
totalRecords = rsCount.getInt(1);
rsCount.close();
//计算出共要显示多少页
int totalPages = totalRecords % pageSize == 0 ? totalRecords / pageSize : totalRecords / pageSize + 1;
//int totalPages = (totalRecords + pageSize - 1) / pageSize;	//共几页

共<%=totalPages %>页&nbsp第<%=pageNo %>页&nbsp
<a href="ShowArticleFlat.jsp?pageNo=<%=1  %>"> << </a>&nbsp
<a href="ShowArticleFlat.jsp?pageNo=<%=pageNo-1 %>"> < </a>&nbsp
<a href="ShowArticleFlat.jsp?pageNo=<%=pageNo+1 %>"> > </a>&nbsp
<a href="ShowArticleFlat.jsp?pageNo=<%=totalPages %>"> >> </a>

<form name="form1" action="ShowArticleFlat.jsp">
  <select name="pageNo" onchange="document.form1.submit()">
  <%
  for(int i = 1; i <= totalPages; i++) {
  %>	
  <option value=<%=i %> <%=pageNo == i ? "selected" : ""%>>第<%=i %>页
  <%
  }
  %>
  </select>
</form>

<form name="form2" action="ShowArticleFlat.jsp">
  <input type="text" name="pageNo" size=4 value=<%=pageNo %> />
  <input type="submit" value="go" />
</form>

你可能感兴趣的:(jsp)