我学习jsp,struts的,想知道如果知道文章太长,怎样实现分页? 

解决方案 »

  1.   

    可以用 http://www.finereport.com 来实现分页,不用写代码
      

  2.   


    struts的分页 是对 记录的分页
      

  3.   

    自己想办法不可以吗?同样是分页,必然有同样的原理啊,普通的分页对记录进行分,那么为什么不把每行的字符串看成一条记录,或者多少个字符看做一条记录???分页技术,无非就是确定一下几个内容
    1. 每页的记录数(这里一行一条记录)
    2. 一共有多少行(每行都是以\r\n结尾,用StringTokenizer就可以算,或者用正则表达式也行)
    3. 可以分多少页(一除就出来了)
    有了这些,再利用分页逻辑,应该是没有问题的,虽然只是猜想。呵呵
      

  4.   

    public String Str(String str)
    {
       if(str.length>numNo)
    {
        return str.subString(0,50)+".........";
    }else
    {
        return str;
    }
    }
    用截取字符的方式来
      

  5.   

    public ActionForward paging(ActionMapping arg0, ActionForm arg1,
                HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
            String currPage = arg2.getParameter("currPage");        int iCurrPage = 1;
            if (currPage != null && !currPage.equalsIgnoreCase("")) {
                iCurrPage = Integer.parseInt(currPage);
            }
            // 每页显示的记录
            int recPerPage = 5;
            // 进行分页查询
            List list = cs.findPaging("from Customer",
                    (iCurrPage - 1) * recPerPage, recPerPage);
            // 获得总记录书
            int count = ((Integer) cs.uniqueResult("select count(*) from Customer"))
                    .intValue();
            // 定义总页数
            int pages = 1;
            // 计算总页数
            if ((count % recPerPage) == 0) {
                pages = count / recPerPage;
            } else {
                pages = count / recPerPage + 1;
            }
            // 构造分页条
            String root = arg2.getContextPath();
            StringBuffer pagingBar = new StringBuffer();
            for (int i = 1; i <= pages; i++) {
                if (i == iCurrPage) {
                    pagingBar.append("&nbsp;&nbsp;<a href='" + root
                            + "/findCustomerAction.do?method=paging&&currPage="
                            + i + "'>[" + i + "]</a>");
                } else {
                    pagingBar.append("&nbsp;&nbsp;<a href='" + root
                            + "/findCustomerAction.do?method=paging&&currPage="
                            + i + "'>" + i + "</a>");
                }        }
            arg2.setAttribute("list", list);
            arg2.setAttribute("pagingBar", pagingBar.toString());
            return arg0.findForward("list");
        }
      

  6.   


    public String StringSub(String str)
    {
       if(str==null)
       {
         return "";
       }
       else(str.lenght>20){ 
      return str.subString(0,20)+"..."
    }
    }