日期:2014-05-17  浏览次数:20699 次

jsp分页?
从表查询的出来信息已经实现了分页效果,可是从表匹配(搜索)出来的信息怎么进行分页?

------解决方案--------------------
mysql sql:select * from user limit 10,10
------解决方案--------------------
我前几天做的分页,楼主参考下吧....
Java code

public class Serch extends ActionSupport
{
   private  String  bid;
   private  String  bname;
   private  int    number;
   private int k;//储存最大页面数
   private int pageNow=1; //页码数,初始为1
   private int pageSize = 5 ; //页面行数 
   private int intRowCount;//总行数
   private int intPageCount;//总页数
   private int lastPage;
   private int p=1;


.....set/get;
public String execute() throws Exception 
{
    List list=new List();
    java.util.List L=new  ArrayList();
    L=list.list();
    intRowCount=L.size();
    System.out.println("链表的长度:"+L.size());
    if(L.size()%pageSize==0) //判断分多少页
          this.lastPage=L.size()/pageSize;
    else
        this.lastPage=L.size()/pageSize+1;
    
    this.setIntPageCount(this.lastPage);//存入总页数
    
    if(this.pageNow<1)//如果当前页码是第一页在点第一页的时候也跳转到第一页
        this.pageNow=1;
    if(this.pageNow>this.lastPage)//同理只不过是最后一页
        this.pageNow=this.lastPage;
    /*
     * 
     * 假设取其中20-25条
     * 
     * 
     * 
     */
  int startIndex=(this.pageNow-1)*pageSize;//截止条目开始,第20条
  int endIndex=startIndex+pageSize;//截止条目结束     第25条
  
  if(endIndex>=L.size())
      endIndex=L.size();
 
  L= L.subList(startIndex, endIndex);
  System.out.println("执行");
  
    ActionContext.getContext().put("list", L);
    return  "success";
}
@Override
public void validate() {
    // TODO Auto-generated method stub
    super.validate();
}


}
前台显示:


共<s:property value="intRowCount"/>记录&nbsp;&nbsp;
共<s:property value="intPageCount"/>页&nbsp;&nbsp;
        第<s:property value="pageNow"/>页&nbsp;&nbsp;
 <s:url action="Serch.action" id="url">
                <s:param name="pageNow">
                    <s:property value="1" />
                </s:param>
            </s:url>
  <s:a href="%{url}">首页</s:a>    &nbsp;&nbsp;
       
       <s:url action="Serch.action" id="url">
                <s:param name="pageNow">
                    <s:property value="%{pageNow-1}" />
                </s:param>
            </s:url>
  <s:a href="%{url}">上一页</s:a>    &nbsp;&nbsp;


 <s:url action="Serch.action" id="url">
                <s:param name="pageNow">
                    <s:property value="%{pageNow+1}" />
                </s:param>
            </s:url>
  <s:a href="%{url}">下一页</s:a>    &nbsp;&nbsp;

<s:url action="Serch.action" id="url">
                <s:param name="pageNow">
                    <s:property value="lastPage" />
                </s:param>
            </s:url>
  <s:a href="%{url}">尾页</s:a>