首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2012-01-18 
搞了三天的分页了!可是这里还是有点问题.高手来指点指点%@pagecontentType text/htmlcharsetGBK lan

搞了三天的分页了!可是这里还是有点问题.高手来指点指点
<%@   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>


            <td> <%=rs.getString( "TELE ")%> </td>
            <td> <input   type= "button "   value= "修改 "   onclick= "self.location.replace( 'uporacle.jsp?id= <%=rs.getString( "id ")%> ') "> </td>
                <td> <input   type= "button "   value= "删除 "   onclick= "self.location.replace( 'deleteora.jsp?id= <%=rs.getString( "id ")%> ') "> </td>
                </tr>
                <%}
                }
   
    }
   

    rs.close();
    stem.close();
    conn.close();
    %>
</table>
<div   align= "center ">
<form   action= "pageora.jsp "   method= "post "   name= "excel ">
<a   href= "pageora.jsp?curPage= <%=currentPage-1   %> "> 上一页 </a>
<a   href= "pageora.jsp?curPage= <%=currentPage+1%> "> 下一页 </a>
当前第 <%=currentPage   %> 页,总共 <%=PageCount%> 页
跳到 <input   type= "text "   name= "curPage "   size= "3 "> 页
<input   type= "submit "   name= "submit "   value= "GO ">
</form> </div>
</body>
</html>


[解决办法]
有什么问题?要对症下药啊.....
[解决办法]
什么问题??

[解决办法]
我帮你改进几个地方:
1、PageCount = (maxrows%rowsPerPage==0)?maxrows/rowsPerPage:(maxrows/rowsPerPage+1);
改为PageCount = (maxrows-1)/rowsPerPage+1;
2、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>
<td> <%=rs.getString( "TELE ")%> </td>
<td> <input type= "button " value= "修改 " onclick= "self.location.replace( 'uporacle.jsp?id= <%=rs.getString( "id ")%> ') "> </td>
<td> <input type= "button " value= "删除 " onclick= "self.location.replace( 'deleteora.jsp?id= <%=rs.getString( "id ")%> ') "> </td>
</tr>
<%}
}

}
if(rs.getRow()> maxrows)
break;
这一块用不着的,删了。
3、rs.absolute(position);这个是绝对定位,假设现在是第一页,那么应该定在一上,那你用rs.next(),那不是从第二条开始了????

逻辑我没有看到错误。你自己在试试。
[解决办法]
http://www.blogjava.net/hmilyld/archive/2007/12/14/spring_struts_hibernate_page.html

前几天写的一个Spring+Struts+Hibernate的分页,模仿Google的分页样式那种.
或许有帮助.:)
------解决方案--------------------


为什么while循环外面又要套一个for循环

热点排行