<  request.setCharacterEncoding("gb2312");int m=0;
    try{
      JdbcBean dbutil = new JdbcBean();
    String condition="select * from cplb";
int rowcount = dbutil.execQueryName(condition);
    ArrayList al = dbutil.getRS();
    for(int i=0;i<rowcount;i++){
     HashMap colValue = (HashMap)al.get(i);  
 m++;
 if(m>7) {break;}
    %>
                    <tr class="padd">
                      <td align="left"><img src="images/active_44.gif" width="9" height="9" alt="ico" /></td>
                      <td align="left"><a href="prcenter.jsp?cplb=<%=(String)colValue.get("cplb")%>" class="pr"><%=(String)colValue.get("cplb")%></a> </td>
                    </tr>
                    <% } %>
                    <%} catch (Exception ex) {ex.printStackTrace();} %>
                    <tr>
                      <td align="left">&nbsp;</td>
                      <td align="left">&nbsp;</td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td><img src="images/active_59.gif" width="180" height="24" alt="003" /></td>
                </tr>
                <tr>
                  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td align="center"><a href="zhongzhi.jsp"><img src="images/active_65.gif" alt="sd" width="147" height="45" border="0" /></a></td>
                    </tr>
                    <tr>
                      <td align="center">&nbsp;</td>
                    </tr>
                    <tr>
                      <td align="center"><a href="contactus.jsp"><img src="images/active_67.gif" alt="" width="147" height="44" border="0" /></a></td>
                    </tr>
                    <tr>
                      <td align="center">&nbsp;</td>
                    </tr>
                    <tr>
                      <td align="center"><a href="liuyan.jsp"><img src="images/active_73.gif" alt="rew" width="142" height="40" border="0" /></a></td>
                    </tr>
                  </table></td>
                </tr>
              </table></td>
              <td align="right" valign="top"><table width="575" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="center"><table width="541" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td><img src="images/active_47.gif" width="541" height="29" alt="pr" /></td>
                        </tr>
                        <tr>
                          <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td>   <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                            <tr>
  
 <%! int pageSize =9;//每页显示的记录
      int pageCount = 0;//总页数
      int showPage =1;//当前显示的页数
      %>
  
                  <%
 request.setCharacterEncoding("gb2312"); 
 int j=-1;  
 try{ String condition="select * from CPmessage";
 String note=request.getParameter("note");
String cplb = new String(request.getParameter("cplb").getBytes("ISO8859_1"));
 if(cplb!=null){condition="select * from CPmessage where cplb='"+cplb+"'";}
 if(note!=null){condition="select * from CPmessage where cpmc like '%"+ note +"%'";}
         JdbcBean dbutil = new JdbcBean();
int lastRow = dbutil.execQueryName(condition);
    ArrayList al = dbutil.getRS();
   pageCount = (lastRow % pageSize == 0) ? (lastRow / pageSize) : (lastRow / pageSize + 1);//固定算法
     String go1=request.getParameter("page");
     if(go1==null)
     { go1="1";
     }
     try{
      showPage=Integer.parseInt(go1);
     }
     catch(NumberFormatException e){
       showPage=1;
       }
     if(showPage<=1)//输入的页数小于则显示第一页
     {  showPage=1;
     }
     if(showPage>=pageCount)//输入的页数大于总页数则显示最后一页
     {  showPage=pageCount;
     }
int posion=(showPage-1)*pageSize;
%>  <strong><%if(cplb!=null){out.print(cplb);}%></strong><%
for(int i=posion;i<posion+pageSize && i<lastRow;i++)
   
 { HashMap colValue = (HashMap)al.get(i);
  String t = (String)colValue.get("img"); j++; 
 
  if(j%3==0){%> <tr><td height="2" bordercolor="#FFFFFF"> </td>
           </tr><%}%>
                              <td bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0" >
                                  <tr>
                                    <td align="center" bordercolor="#FFFFFF"><a href="prcenter_temple.jsp?id=<%=(String)colValue.get("id")%>" target="_blank"><img src="<%=t%>" width="130" height="110" border="0" /></a></td>
                                  </tr>
                                  <tr>
                                    <td align="center" bordercolor="#FFFFFF"><a href="prcenter_temple.jsp?id=<%=(String)colValue.get("id")%>" target="_blank"><%=(String)colValue.get("cpmc")%> </a></td>
                                  </tr> 
                              </table></td>

  
<%}%>  </table></td>
                              </tr>
                            <tr>
                              <td align="center"><div align="right"> 
                                <form name="form1" id="form1" method="post" action="prcenter.jsp">
                                  共<%=pageCount%>页&nbsp;<%=lastRow%>条数据&nbsp; 当前第 <%=showPage%>/<%=pageCount%>页 
                                  &nbsp; 
                                  <%if (showPage>1){%>
                                  <a href="prcenter.jsp?page=1">[首页]</a>&nbsp;<a href="prcenter.jsp?page=<%=showPage-1%>">[上一页]</a> 
                                  <%}else{%>
                                  [第一页]&nbsp;[上一页] 
                                  <%}
         if (showPage< pageCount) {%>
                                  &nbsp;<a href="prcenter.jsp?page=<%=showPage+1%>">[下一页]</a>&nbsp;<a href="prcenter.jsp?page=<%=pageCount%>">[尾页]</a> 
                                  <%}else{%>
                                  &nbsp;[下一页]&nbsp;[最后页] 
                                  <%}%>
                                  转到第 
                                  <select onChange="gotoPageBottom('self',this,0)" name="jumpPageBottom">
                                    <%for(int w=1;w<=pageCount;w++){%>
                                    <option value="2"><%=w%></option>
                                    <%}%>
                                  </select>
                                  页
                                  <input type="submit" name="Submit" value="GO" />
                                </form>
                              </div></td>
                              </tr>
                          </table><%} catch (Exception ex) {out.print("查询不到该产品!");} %>  </td>
                        

解决方案 »

  1.   

    看看这个:
    http://topic.csdn.net/u/20090109/19/5b0fdf74-4767-4c3c-8dc3-183efedb7a94.html<%@ page contentType="text/html;charset=gb2312" %>
    <%@ page language="java" import="java.sql.*" %><script language="javascript">
    function newwin(url) {
    var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
    newwin.focus();
    return false;
    }
    </script>
    <script LANGUAGE="javascript">
    function submit10()
    {
    self.location.replace("fenye1.jsp")
    }
    </script>
    <%//变量声明
    java.sql.Connection sqlCon; //数据库连接对象
    java.sql.Statement sqlStmt; //SQL语句对象
    java.sql.ResultSet sqlRst; //结果集对象
    java.lang.String strCon; //数据库连接字符串
    java.lang.String strSQL; //SQL语句
    int intPageSize; //一页显示的记录数
    int intRowCount; //记录总数
    int intPageCount; //总页数
    int intPage; //待显示页码
    java.lang.String strPage;
    int i;
    //设置一页显示的记录数
    intPageSize = 4;
    //取得待显示页码
    strPage = request.getParameter("page");
    if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
    intPage = 1;
    }
    else{//将字符串转换成整型
    intPage = java.lang.Integer.parseInt(strPage);
    if(intPage<1) intPage = 1;
    }
    //装载JDBC驱动程序
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //设置数据库连接字符串
    strCon = "jdbc:odbc:heyang";
    //连接数据库
    sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","");
    //创建一个可以滚动的只读的SQL语句对象
    sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);//准备SQL语句
    strSQL = "select user_id,user_name from userinfo order by user_id desc";
    //执行SQL语句并获取结果集
    sqlRst = sqlStmt.executeQuery(strSQL);
    //获取记录总数
    sqlRst.last();//??光标在最后一行
    intRowCount = sqlRst.getRow();//获得当前行号
    //记算总页数
    intPageCount = (intRowCount+intPageSize-1) / intPageSize;
    //调整待显示的页码
    if(intPage>intPageCount) intPage = intPageCount;
    %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>会员管理</title>
    </head>
    <body>
    <form method="POST" action="fenye1.jsp">
    第<%=intPage%>页  共<%=intPageCount%>页  <%if(intPage<intPageCount){%><a href="fenye1.jsp?page=<%=intPage+1%>">下一页</a><%}%>  <%if(intPage>1){%><a href="fenye1.jsp?page=<%=intPage-1%>">上一页</a><%}%>
    转到第:<input type="text" name="page" size="8"> 页
    <span><input class=buttonface type=´submit´ value=´GO´ name=´cndok´></span>
    </form>
    <table border="1" cellspacing="0" cellpadding="0">
    <tr>
    <th>ID</th>
    <th>用户名</th>
    <th width=´8%´>删除</th>
    </tr>
    <%
    if(intPageCount>0){
    //将记录指针定位到待显示页的第一条记录上
    sqlRst.absolute((intPage-1) * intPageSize + 1);
    //显示数据
    i = 0;
    String user_id,user_name;
    while(i<intPageSize && !sqlRst.isAfterLast()){
    user_id=sqlRst.getString(1);
    user_name=sqlRst.getString(2);
    %>
    <tr>
    <td><%=user_id%></td>
    <td><%=user_name%></td>
    <td width=´8%´ align=´center´><a href="delete.jsp?user_id=<%=user_id%>" onClick="return newwin(this.href);">删除</a></td>
    </tr>
    <%
    sqlRst.next();
    i++;
    }
    }
    %>
    </table>
    </body>
    </html>
    <%
    //关闭结果集
    sqlRst.close();
    //关闭SQL语句对象
    sqlStmt.close();
    //关闭数据库
    sqlCon.close();
    %>