给你一个分页类,直接在action里调用就可以了,代码给你贴出来!
----------------------------------------------------------------------------------
分页类:
public class MyPageList {
private PagedListHolder pagedlist;
public static final int PAGESIZE = 15; // 每页显示几条记录
public MyPageList(List list) {
this.pagedlist = new PagedListHolder(list);
}
public List getInstance() {
pagedlist.setPageSize(PAGESIZE);
return pagedlist.getPageList();
}
public List getInstance(int PAGESIZE) {
pagedlist.setPageSize(PAGESIZE);
return pagedlist.getPageList();
}
public List next() {//下一页
pagedlist.nextPage();
return pagedlist.getPageList();
}
public List prep() {//上一页
pagedlist.previousPage();
return pagedlist.getPageList();
}
public List first() {//首页
for (int i = 0; i < pageCount(); i++) {
if (pagedlist.isFirstPage()) {
break;
}
pagedlist.previousPage();
}
return pagedlist.getPageList();
}
public List last() {//最后一页
for (int i = 0; i < pageCount(); i++) {
if (pagedlist.isLastPage()) {
break;
}
pagedlist.nextPage();
}
return pagedlist.getPageList();
}
public int pageCount() {//总共多少页
return pagedlist.getPageCount();
}
public int pageNumber() {//第几页
return pagedlist.getPage() + 1;
}
}
----------------------------------------------------------------------------------
action中的代码:
MyPageList myPageList = null;
public ActionForward doPage(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
String op=request.getParameter("op");
List list=new ArrayList();
if(op != null)
{
if(op.equals("prep"))
{
list=myPageList.prep();
}
else if(op.equals("next"))
{
list=myPageList.next();
}
else if(op.equals("first"))
{
list=myPageList.first();
}
else if(op.equals("last"))
{
list=myPageList.last();
}
}
request.getSession().setAttribute("warnList", list);
request.getSession().setAttribute("pageNumber", myPageList.pageNumber());
return mapping.findForward("warnInfo");
}
----------------------------------------------------------------------------------
页面中的代码:
<td>
<a href="warn.do?method=doPage&op=first"> 第一页 </a>
</td>
<td>
<a href="warn.do?method=doPage&op=prep"> 上一页 </a>
</td>
<td>
<a href="warn.do?method=doPage&op=next">下一页 </a>
</td>
<td>
<a
href="warn.do?method=doPage&op=last"> 最后页 </a>
</td>