这个给你作参考,里面有分页代码。<%@ page contentType="text/html;charset=gb2312" %><%@ page errorPage="../error.jsp"%><%
//判断是否有权限String purview=(String)session.getValue("purview");
    if(purview.charAt(0)!='5'&&purview.charAt(0)!='0'){
   out.print("<body background='../manager/images/bj-1.jpg'><div align=center valign=middle><br><br><br><br><br><img src='../manager/images/qx.gif'></div></body>");
   }
   else{
%><html>
<head>
<title>新闻管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../guestbook.css" type="text/css"><script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<script language=javascript>
function isValid(form){
    if(form.text.value==""){
        alert("内容不能为空!");
return false;
    }
    if(form.text1.value==""||(form.text1.value.indexOf("<") != -1)||(form.text1.value.indexOf(">") != -1)){
        alert("内容不能为空或包括“<”和“>”!");
return false;
    }
}
</script>
<style type="text/css">
<!--
.text_indent {  text-indent: 18pt}
.large_text {  font-size: 10.5pt}
-->
</style>
</head>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="news" scope="page" class="CommunityDB.CommunityDB" /> <%
//分页
int pageLine=10;
int totalRec=0;
int totalSub=0;
int pageNo=1;if (request.getParameter("page")!=null)
pageNo=Integer.parseInt(request.getParameter("page"));
if(pageNo<=1)
pageNo=1;try{
ResultSet countrs=null;
//指定参考行数//取得总数
countrs=news.executeQuery("select count(*) as cnt from news ");
if (countrs.next())
 totalRec=countrs.getInt("cnt");
countrs.close();
news.closeStmt();
//取得主题数
countrs=news.executeQuery("select count(*) as cnt from news where newstype='community'");
if (countrs.next())
 totalSub=countrs.getInt("cnt");
countrs.close();
news.closeStmt();
}
catch(Exception e){
   e.printStackTrace();
}//取得每行的主题数量
int jtemp=totalRec/pageLine+1;
int totalSubPerPage=totalSub/jtemp;
//取得总页数int totalPage=0;
totalPage=(totalSub+pageLine-1)/pageLine;
  if(pageNo>=totalPage)
  pageNo=totalPage;  
%>
<%
int id=0;
 int ifshow=0;
  String sql="select * from news where newstype='community' order by newsid DESC";
  ResultSet rs = news.executeQuery(sql); 
  %>
<body bgcolor="ffffff" text="#000000" topmargin="0" leftmargin="0" rightmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="60">
  <tr>
    <td bgcolor="f58220" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60">
        <param name=movie value="image/banner.swf">
        <param name=quality value=high>
        <embed src="image/banner.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">
        </embed> 
      </object></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="17">
  <tr> 
    <td align="left" height="13"><img src="../images/manage_corner.gif" width="22" height="21"></td>
  </tr>
</table>
<br>
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td width="60%"><img src="../images/news_manage.gif" width="264" height="26"></td>
    <td width="17%"><a href="news_manage.jsp?page=<%=pageNo-1%>">&gt;&gt; 上一页</a></td>
    <td width="23%"><a href="news_manage.jsp?page=<%=pageNo+1%>"> &gt;&gt; 下一页</a></td>
  </tr>
</table>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="ff6699">
  <%
  int i=0;
    while(rs.next()){
i++;
   if(i>(pageLine *(pageNo-1)) && (i<=(pageNo * pageLine))){

id=rs.getInt("newsid");
%>
  <tr bgcolor="#FFdddd" valign="middle"> 
    <td height="18" width="68%" class="text_indent"> 
      <p onClick=MM_openBrWindow('news_browse.jsp?newsid=<%=id%>','新闻','scrollbars=yes')><a href=#><%=rs.getString("NEWSTITLE")%></a></p>

  
  
  
  
  
  </td>
    <td height="18" width="17%" align="center"><%=rs.getDate("NEWSDATE")%></td>
 
    <td height="18" width="15%" align="center"><a href="news_del.jsp?id=<%=id%>">删除</a></td>
  </tr>
  <%
  }}
  rs.close();%>
</table>
<div align="center"> 
  <%
 out.print("<p><br>共有新闻"+ totalSub + "条,分为" + totalPage + "页显示  ");
 for(int j=1;j<=totalPage;j++){
   if(j%10==0) out.print("<br>");
   out.print("<a href=news_manage.jsp?page=" + j + ">");
   if (j==pageNo)
       out.print("<font color='red'>" + j + "</font>");
   else
    out.print(j);
   out.print("</a> ");
}
out.print("<br>");
%>
  <br>
  <table width="80%" border="0" cellpadding="0" cellspacing="1">
    <tr> 
      <td width="100%"><img src="../images/add_news.gif" width="264" height="26"></td>
    </tr>
  </table>
  <table width="80%" border="0" height="162" cellpadding="0" cellspacing="1" style="border:1 solid f58220">
    <tr> 
      <td align="center"> 
        <form name="form1" method="post" action="news_doadd.jsp" onSubmit="return isValid(this)">
          <br>
          标题 
          <p>
<input type="text" name="text1" size="60" style="border:1 solid f58220">
          </p>
          <p><br>
            内容<br>
            <textarea name="text" cols="70" rows="9" style="font-size:9pt;border: 1 solid"></textarea>
            <br>
            <input type="submit" name="Submit" value="添加">
          </p>
        </form>
      </td>
    </tr>
    
  </table>
  <br>
</div>
</body>
</html>
<%}%>

解决方案 »

  1.   

    这个给你作参考,里面有分页代码。<%@ page contentType="text/html;charset=gb2312" %><%@ page errorPage="../error.jsp"%><%
    //判断是否有权限String purview=(String)session.getValue("purview");
        if(purview.charAt(0)!='5'&&purview.charAt(0)!='0'){
       out.print("<body background='../manager/images/bj-1.jpg'><div align=center valign=middle><br><br><br><br><br><img src='../manager/images/qx.gif'></div></body>");
       }
       else{
    %><html>
    <head>
    <title>新闻管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel="stylesheet" href="../guestbook.css" type="text/css"><script language="JavaScript">
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    //-->
    </script>
    <script language=javascript>
    function isValid(form){
        if(form.text.value==""){
            alert("内容不能为空!");
    return false;
        }
        if(form.text1.value==""||(form.text1.value.indexOf("<") != -1)||(form.text1.value.indexOf(">") != -1)){
            alert("内容不能为空或包括“<”和“>”!");
    return false;
        }
    }
    </script>
    <style type="text/css">
    <!--
    .text_indent {  text-indent: 18pt}
    .large_text {  font-size: 10.5pt}
    -->
    </style>
    </head>
    <%@ page language="java" import="java.sql.*" %>
    <jsp:useBean id="news" scope="page" class="CommunityDB.CommunityDB" /> <%
    //分页
    int pageLine=10;
    int totalRec=0;
    int totalSub=0;
    int pageNo=1;if (request.getParameter("page")!=null)
    pageNo=Integer.parseInt(request.getParameter("page"));
    if(pageNo<=1)
    pageNo=1;try{
    ResultSet countrs=null;
    //指定参考行数//取得总数
    countrs=news.executeQuery("select count(*) as cnt from news ");
    if (countrs.next())
     totalRec=countrs.getInt("cnt");
    countrs.close();
    news.closeStmt();
    //取得主题数
    countrs=news.executeQuery("select count(*) as cnt from news where newstype='community'");
    if (countrs.next())
     totalSub=countrs.getInt("cnt");
    countrs.close();
    news.closeStmt();
    }
    catch(Exception e){
       e.printStackTrace();
    }//取得每行的主题数量
    int jtemp=totalRec/pageLine+1;
    int totalSubPerPage=totalSub/jtemp;
    //取得总页数int totalPage=0;
    totalPage=(totalSub+pageLine-1)/pageLine;
      if(pageNo>=totalPage)
      pageNo=totalPage;  
    %>
    <%
    int id=0;
     int ifshow=0;
      String sql="select * from news where newstype='community' order by newsid DESC";
      ResultSet rs = news.executeQuery(sql); 
      %>
    <body bgcolor="ffffff" text="#000000" topmargin="0" leftmargin="0" rightmargin="0">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" height="60">
      <tr>
        <td bgcolor="f58220" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60">
            <param name=movie value="image/banner.swf">
            <param name=quality value=high>
            <embed src="image/banner.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">
            </embed> 
          </object></td>
      </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" height="17">
      <tr> 
        <td align="left" height="13"><img src="../images/manage_corner.gif" width="22" height="21"></td>
      </tr>
    </table>
    <br>
    <table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr> 
        <td width="60%"><img src="../images/news_manage.gif" width="264" height="26"></td>
        <td width="17%"><a href="news_manage.jsp?page=<%=pageNo-1%>">&gt;&gt; 上一页</a></td>
        <td width="23%"><a href="news_manage.jsp?page=<%=pageNo+1%>"> &gt;&gt; 下一页</a></td>
      </tr>
    </table>
    <table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="ff6699">
      <%
      int i=0;
        while(rs.next()){
    i++;
       if(i>(pageLine *(pageNo-1)) && (i<=(pageNo * pageLine))){

    id=rs.getInt("newsid");
    %>
      <tr bgcolor="#FFdddd" valign="middle"> 
        <td height="18" width="68%" class="text_indent"> 
          <p onClick=MM_openBrWindow('news_browse.jsp?newsid=<%=id%>','新闻','scrollbars=yes')><a href=#><%=rs.getString("NEWSTITLE")%></a></p>

      
      
      
      
      
      </td>
        <td height="18" width="17%" align="center"><%=rs.getDate("NEWSDATE")%></td>
     
        <td height="18" width="15%" align="center"><a href="news_del.jsp?id=<%=id%>">删除</a></td>
      </tr>
      <%
      }}
      rs.close();%>
    </table>
    <div align="center"> 
      <%
     out.print("<p><br>共有新闻"+ totalSub + "条,分为" + totalPage + "页显示  ");
     for(int j=1;j<=totalPage;j++){
       if(j%10==0) out.print("<br>");
       out.print("<a href=news_manage.jsp?page=" + j + ">");
       if (j==pageNo)
           out.print("<font color='red'>" + j + "</font>");
       else
        out.print(j);
       out.print("</a> ");
    }
    out.print("<br>");
    %>
      <br>
      <table width="80%" border="0" cellpadding="0" cellspacing="1">
        <tr> 
          <td width="100%"><img src="../images/add_news.gif" width="264" height="26"></td>
        </tr>
      </table>
      <table width="80%" border="0" height="162" cellpadding="0" cellspacing="1" style="border:1 solid f58220">
        <tr> 
          <td align="center"> 
            <form name="form1" method="post" action="news_doadd.jsp" onSubmit="return isValid(this)">
              <br>
              标题 
              <p>
    <input type="text" name="text1" size="60" style="border:1 solid f58220">
              </p>
              <p><br>
                内容<br>
                <textarea name="text" cols="70" rows="9" style="font-size:9pt;border: 1 solid"></textarea>
                <br>
                <input type="submit" name="Submit" value="添加">
              </p>
            </form>
          </td>
        </tr>
        
      </table>
      <br>
    </div>
    </body>
    </html>
    <%}%>
      

  2.   

    http://www.csdn.net/expert/topic/780/780048.xml?temp=.1294367
    http://www.csdn.net/expert/topic/771/771284.xml?temp=.8465845
    搜索一下分页,太多了!