找一个最好的JSP分页Tag。连接数据库使用的是hibernate

解决方案 »

  1.   

    呵呵,我做的是mvc模式,水平有限。
      

  2.   

    http://jsptags.com/楼主自己看看吧,我也是刚刚看到的,也没弄过good luck
      

  3.   

    参考下吧。。
    http://hi.baidu.com/%CC%EC%CF%C2%CE%DE%C0%B6/blog/item/e6492cfd13e44142d7887d13.html
      

  4.   

    参考<% request.setCharacterEncoding("UTF-8");
               String zttype = request.getParameter("zt_type");
               if(zttype==null){zttype="all";}
    String strpageNo = request.getParameter("pageNo");
    int pageNo = 1;
    if(strpageNo==null||strpageNo.equals("")){
    pageNo =1;
    }else{
    try{
    pageNo = Integer.parseInt(strpageNo);
    }catch(NumberFormatException e){
    pageNo=1;
    }
    if(pageNo<=0){
    pageNo=1;
    }
    }
    int totalPages = 0;//总共多少页
          int pageSize = 3;// 每页显示几条
         boolean flag = false;//声明一个boolean变量,用于判断是否有内容,根据flag来做出提示
         ResultSet rs = null;
         int pagePos = 0; //显示的起始位置
         int lastPage = 0;
         try{
         rs = newutil.findCount(zttype);
         rs.next();
         //首先得到记录的总条数
                    int totalRecords = rs.getInt(1);
                 //看一共要分几页,是你的pagesize决定的(每页显示几条)
                 totalPages = totalRecords % pageSize == 0 ? totalRecords/ pageSize : totalRecords / pageSize + 1;
                    lastPage = totalPages;
                 //比如共能分2页,你输入显示第三页,那就不ok了,大于了,就显示最后一页
                 if (pageNo > totalPages){
                      pageNo = totalPages;
         }
                  pagePos =(pageNo - 1) * pageSize;}
         catch(Exception e){}
     

    rs = newutil.select(pagePos,pageSize,zttype);
    while(rs.next()){
    long id = rs.getLong(1);
    String title = rs.getString(2);
    Date time = rs.getDate(4);
    String type = rs.getString(6);
    %>
    <tr><td align="left"><img src="images/dot_main01.gif">&nbsp;&nbsp;<a href="/toba/showNew.jsp?newId=<%=id%>" target="show1"><%=title%></a></td><td><%=type %></td><td><%=time %></td></tr>
    <%
    }
    %>
    <tr><td align="center">共<%=totalPages%>页&nbsp;第<%=pageNo%>页&nbsp;<a href="news.jsp?pageNo=<%=pageNo - 1 %>&zt_type=<%=zttype%>"  onclick="return linkClick(this)">上一页</a>&nbsp;<a href="news.jsp?pageNo=<%=pageNo + 1 %>&zt_type=<%=zttype%>" onclick="return linkClick(this)">下一页</a>&nbsp;<a href="news.jsp?pageNo=<%=lastPage %>&zt_type=<%=zttype%>" onclick="return linkClick(this)">尾页</a></td></tr>
    </table><center><%for(int i=1;i<=totalPages;i++){
    %><a href="news.jsp?pageNo=<%=i %>&zt_type=<%=zttype%>"  onclick="return linkClick(this)"><%=i %></a>&nbsp;
    <%} %></center>
    </td>
            </tr>
          </table>
      

  5.   

    java代码public ResultSet findCount(String type) throws Exception {
    Session session = HbnUtil.getSession();
    Connection connection = session.connection();
    Statement sts = connection.createStatement();
    String sql = null;
    if (type==null||type.equals("all")) { 
    sql = "select count(*) from new_t";
    } else {
    System.out.println((String)type);
    sql = "select count(*) from new_t where zt_type=" + "'"
    + (String)type + "'";
    }
    return sts.executeQuery(sql);
    } public ResultSet select(int pagePos, int pageSize, String type)
    throws Exception {
    Session session = HbnUtil.getSession();
    Connection connection = session.connection();
    String sql = null;
    PreparedStatement pstmt = null;
    if (type==null||type.equals("all")) {
    sql = "select * from new_t order by zt_id desc limit " + pagePos + "," + pageSize;
    } else {
    sql = "select * from new_t " + "where zt_type=" + "'"
    + type + "'" + " order by zt_id desc limit " + pagePos + ","
    + pageSize;
    }
    pstmt = connection.prepareStatement(sql);
    return pstmt.executeQuery();
      

  6.   

    java很有意思,居然没有一个公认的分页。http://jsptags.com是一次性取出,不适用。