当前位置: 代码迷 >> Java Web开发 >> 搞了三天的分页了!可是这里还是有点有关问题.高手来指点指点
  详细解决方案

搞了三天的分页了!可是这里还是有点有关问题.高手来指点指点

热度:106   发布时间:2016-04-17 14:20:12.0
搞了三天的分页了!可是这里还是有点问题.高手来指点指点
<%@   page   contentType= "text/html;   charset=GBK "   language= "java "   import= "java.sql.*,java.io.* "   %>
<html>
<head>
<title>
</title>
</head>
<body   bgcolor= "#ffffff ">
<h1   align= "center ">
</h1>
<table   border= "2 "   align= "center ">
<tr> <td> 编号 </td> <td> 名字 </td> <td> 地址 </td> <td> 电话 </td> </tr>
<%!String   trans(String   chi)
{
    String   result   =   null;
    byte   temp[];
    try
    {
        temp   =   chi.getBytes( "iso-8859-1 ");
        result     =   new   String(temp);
    }
    catch(UnsupportedEncodingException   e)
    {
        System.out.println(e.toString());
    }
    return   result;
}

%>
<%
int   currentPage=1;
int   rowsPerPage=10;
int   maxrows=0;
Class.forName( "oracle.jdbc.driver.OracleDriver ").newInstance();
Connection   conn   =   java.sql.DriverManager.getConnection( "jdbc:oracle:thin:@122.48.118.151:1521:smsdb ", "paxw ", "paxw872930 ");
Statement   stem   =   conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet   rs   =   stem.executeQuery( "select   *   from   t_paxw_hm ");
int   PageCount=0;
int   position;
if(rs!=null)
{
    rs.last();
    maxrows   =   rs.getRow();
    PageCount   =   (maxrows%rowsPerPage==0)?maxrows/rowsPerPage:(maxrows/rowsPerPage+1);
    String   strCurPage   =   request.getParameter( "curPage ");    
    if(strCurPage==null)
    {
        currentPage=1;
    }
    else
    {
        currentPage=Integer.parseInt(strCurPage);
    }
    if(currentPage> PageCount)
    {
        currentPage=PageCount;
    }
    if(currentPage <1)
    {
        currentPage=1;
    }
    position   =   (currentPage-1)*rowsPerPage+1;
    System.out.println( "position   is   "+position   );
    rs.absolute(position);


    for(int   i=0;i <rowsPerPage;i++)
    {
        if(rs.getRow()> maxrows)
        break;
       
       
        %>
        <%while(rs.next())   {%>
        <tr>
            <td> <%=rs.getString( "id ")%> </td>
            <td> <%=rs.getString( "HM_NAME ")%> </td>
            <td> <%=rs.getString( "HM_ADDRESS ")%> </td>
  相关解决方案