做WEB方面免不了分页技术,我最近想研究研究,谁有空帮我写个简单的分页,ssh的或jsp的分页都行。
请把您的项目直接发到[email protected]邮箱中,谢谢。别忘了,在这里发条信息,好给您分呀。

解决方案 »

  1.   

    下个displaytag 吧……
    非常简单
      

  2.   

    displaytag
    与Struts结合使用最出名的一个tag主要是显示表格数据很漂亮、完善。
      

  3.   

    网上有这样的自定义标签,根本不用自己再写的
    如ipager3.0
    还有display tag
    只要在lib下加上相关的jar,视图层页面加上3行标签就完事 
      

  4.   

    我的是纯JSP 的分页 数据库是mysql的 我验证过 没问题的 压缩包名  page(纯 JSP).rar发给你 行的话  加分啊
      

  5.   

    http://www.javaresearch.org/article/8893.htm
    这儿有详细的解释
      

  6.   

    谢谢各位的踊跃发言,上面有个仁兄写了一个,我看了是在JSP中直接嵌套JAVA代码,是我的疏忽,忘了告诉你们这样写可能不太好,在实际的项目中可能不会用到,不过还是要谢谢他,我会仔细看看的。希望各位大侠在百忙之中能抽空照顾一下小弟,再此感谢不尽。
      

  7.   

    http://code.google.com/p/smartpagination/source/browse/trunk/src/org/powerstone/smartpagination/sample/SamplePagingController.java
      

  8.   

    写个PageInfo类.
    然后函数查询的时候把它带上.List<Department> deps = db.from(Department.class).where(criteria, params).getPagedList(pageInfo);public class PageInfo implements Serializable { private int currentPage = 0; private int rowsPerPage = 20; private long total = -1;
    /**
     * @param rows
     * @param rowsPerPage
     * @param currentPage
     */
    public PageInfo() {
    } public PageInfo(int rowsPerPage) {
    this.rowsPerPage = rowsPerPage;
    } /**
     * @return Returns the currentPage.
     */
    public int getCurrentPage() {
    return currentPage;
    } /**
     * @param currentPage
     *            The currentPage to set.
     */
    public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
    } /**
     * @return Returns the rowsPerPage.
     */
    public int getRowsPerPage() {
    return rowsPerPage;
    } /**
     * @param rowsPerPage
     *            The rowsPerPage to set.
     */
    public void setRowsPerPage(int rowsPerPage) {
    this.rowsPerPage = rowsPerPage;
    } /**
     * @return Returns the total.
     */
    public long getTotal() {
    return total;
    } /**
     * @param total
     *            The total to set.
     */
    public void setTotal(long total) {
    this.total = total;
    }
    /**
     * @return Returns the total.
     */
    public int getStartIndex() {
    return currentPage * rowsPerPage;
    } /**
     * @return Returns the total.
     */
    public long getLastIndex() {
    int lastIndex = (currentPage + 1) * rowsPerPage - 1;
    return (lastIndex >= total ? total - 1 : lastIndex);
    } /**
     * 
     */
    public String toString() {
    return currentPage + "_" + rowsPerPage;
    } /**
     * 
     * @return
     */
    public boolean getHasPrev() {
    return currentPage > 0;
    } /**
     * 
     * @return
     */
    public boolean getHasNext() {
    return (currentPage + 1) * rowsPerPage < total;
    } /**
     * 
     * @return
     */
    public PageInfo getPrev() {
    if (currentPage > 0) {
    PageInfo prev = new PageInfo();
    prev.currentPage = currentPage - 1;
    prev.total = total;
    prev.rowsPerPage = rowsPerPage;
    return prev;
    } else {
    return this;
    }
    } /**
     * 
     * @return
     */
    public PageInfo getNext() {
    if ((currentPage + 1) * rowsPerPage < total) {
    PageInfo next = new PageInfo();
    next.currentPage = currentPage + 1;
    next.total = total;
    next.rowsPerPage = rowsPerPage;
    return next;
    } else {
    return this;
    }
    }

    /**
     * 
     * @return
     */
    public int getTotalPageNum() {
    double p = (double)total / rowsPerPage;
    return (int) p + (p - (int)p > 0 ? 1:0);
    } /**
     * 
     * @param str
     * @param rowsPerPage
     * @return
     */
    public static PageInfo valueOf(String str) {
    PageInfo pageInfo = new PageInfo();
    if (str == null || str.length() == 0) {
    pageInfo.currentPage = 0;
    pageInfo.rowsPerPage = 15;
    } else {
    try {
    int n = str.indexOf('_');
    if (n > 0) {
    pageInfo.currentPage = Integer.parseInt(str.substring(0, n));
    pageInfo.rowsPerPage = Integer.parseInt(str.substring(n + 1));
    } else {
    pageInfo.currentPage = 0;
    pageInfo.rowsPerPage = Integer.parseInt(str);
    }
    } catch (NumberFormatException e) {
    }
    }
    return pageInfo;
    }
    }
    在模板里调用这个PageInfo来写分页,给你一个Freeer宏的例子:
    <#macro page_info>
      <div style="float:right">
       <span class="paging">
       <#assign min=pageInfo.currentPage-4>
       <#if (min < 0) >
       <#assign min=0>
       </#if>
       <#if (min > 0) >
       <span class="pageno"><a href="${request.requestURL}?page=0">1</a></span>
       </#if>
       <#assign max=pageInfo.currentPage-1>
       <#if (max < 0) >
       <#assign max=0>
       </#if>
       <#if (max>4)>
       ...
       </#if>
       <#if (pageInfo.currentPage>0)>
       <#list min..max as p >
       <span class="pageno"><a href="${request.requestURL}?page=${p}">${p+1}</a></span>
       </#list>
       </#if>
       <span class="pageno on">
       <a href="${request.requestURL}?page=${pageInfo.currentPage}">${pageInfo.currentPage+1}</a>
       </span>
       <#assign min=pageInfo.currentPage+1>
       <#if (min > pageInfo.totalPageNum -1) >
       <#assign min=pageInfo.totalPageNum - 1>
       </#if>
       <#assign max=pageInfo.currentPage+4>
       <#if (max > pageInfo.totalPageNum-1) >
       <#assign max=pageInfo.totalPageNum-1>
       </#if>
     
       <#if (pageInfo.currentPage<pageInfo.totalPageNum-1)>
       <#list min..max as p >
       <span class="pageno"><a href="${request.requestURL}?page=${p}">${p+1}</a></span>
       </#list>
       </#if>
      <#if (max<pageInfo.totalPageNum-2)>
       ...
       </#if>
       <#if (max<pageInfo.totalPageNum-1)>
         <span class="pageno"><a href="${request.requestURL}?page=${pageInfo.totalPageNum-1}">${pageInfo.totalPageNum}</a></span>
       </#if>
       <span class="matter">(${pageInfo.total}件)</span>
       &nbsp;
       <span class="prev">
       <#if pageInfo.hasPrev>
       <a href="${request.requestURL}?page=${pageInfo.prev.currentPage}">前へ</a>
       <#else>
       前へ
       </#if></span>&nbsp;|&nbsp;
       <span class="next">
       <#if pageInfo.hasNext>
       <a href="${request.requestURL}?page=${pageInfo.next.currentPage}">次へ</a>
       <#else>
       次へ
       </#if>
       </span>
       </span>
      </div>
    </#macro>
      

  9.   

    回复 ivorytower:
        这代码看不懂。
    回复 runffer_yang:
        帮我整理整理,发个项目过来多好呀。
      

  10.   

    后台分页代码
    public List<FoodBean> GetFoods(int page,int count) {
    // TODO Auto-generated method stub
    int start = 0;
    if(page!=1)
    start = (page-1)*count;
    String sql = "select top "+count +" * from foodInfo where foodId not in(select top "+ start +" foodId from foodInfo" + ")";
    ResultSet rs = BaseDao.getResultSet(sql);
    List<FoodBean> list = new ArrayList<FoodBean>();
    try {
    while(rs.next()){
    FoodBean food = new FoodBean();
    food.setDescription(rs.getString("description"));
    food.setFoodId(rs.getString("foodId"));
    food.setFoodImage(rs.getString("foodImage"));
    food.setFoodName(rs.getString("foodName"));
    food.setFoodPrice(rs.getDouble("foodPrice"));
    food.setRe(rs.getString("re"));
    list.add(food);
    }
    BaseDao.closeResultSet(rs);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return list;
    } public int getPageCount(int count) {
    // TODO Auto-generated method stub
    String sql = "select count(1) from foodinfo";
    Connection conn=BaseDao.GetConnection();
    int page = 0;
    try {
    PreparedStatement psmt = conn.prepareStatement(sql);
    ResultSet rs = psmt.executeQuery();
    if(rs.next())
    page = rs.getInt(1);
    rs.close();
        BaseDao.closeStaement(psmt);
        BaseDao.closeConnection(conn);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    if(page/count==0) page = 1;
    if(page/count>0&&page%count==0) page = page/count;
    if(page/count>0&&page%count!=0) page = page/count + 1;
    return page;
    }
      

  11.   

    哥们,你写的非常好,能整合整合,别在JSP页面中写JAVA代码吗?
      

  12.   

    我有现成的,只要传几个参数就可以了package com.zhangmingliang.netshop.util;public class PageNavigation {

    //pageSize 每页记录数 
    //resultSize 总记录数
    public static int getMaxPage(int pageSize,int resultSize)
    {
    return (resultSize+pageSize-1)/pageSize;
    }
    //url 请求的链接
    //pageIndex 当前索引
     // maxPage 最大页数
    public static String getPageNavigation(String url,int pageIndex,int maxPage)
    {
    StringBuilder sb=new StringBuilder("");
    sb.append("");
    sb.append("第"+(pageIndex+1)+"/"+maxPage+"页");
    if(pageIndex>0)
    {
    sb.append("<a href='"+url+"?pageIndex=0'>首页</a>");
    sb.append("<a href='"+url+"?pageIndex="+(pageIndex-1)+"'>上一页</a>");
    }
    else
    {
    sb.append("首页");
    sb.append("上一页");
    }
    if(pageIndex<maxPage-1)
    {
    sb.append("<a href='"+url+"?pageIndex="+(pageIndex+1)+"'>下一页</a>");
    sb.append("<a href='"+url+"?pageIndex="+(maxPage-1)+"'>尾页</a>");
    }
    else
    {
    sb.append("下一页");
    sb.append("尾页");
    }
    sb.append("");
    return sb.toString();
    }}
      

  13.   

       恩  简单写个java类就可以了   网上也有很多相应的框架 可以参考一下