Java Oracle分页处理
package com.list.struts.util; import java.util.ArrayList; public class Page { //当前跳转的页面情况 private String pagetype; private PaginationBean pagination; private ArrayList result; //构造函数实例化接收一个pagetype和PaginationBean对象 public Page(String pagetype, PaginationBean pagination) { this.pagetype = pagetype; this.pagination = pagination; } /** * <p> * </p> */ public boolean isEmpty() { if (pagetype == null || pagetype.equals("")) { return true; } else { return false; } } /** * <p> * </p> * */ public ArrayList getResult() { if (!isEmpty()) { if (pagetype.equals("nextPage")) { result = pagination.getNextPage(); } else if (pagetype.equals("previousPage")) { result = pagination.getPreviouspage(); } else if (pagetype.equals("lastPage")){ result = pagination.getLastPage(); } else if (pagetype.equals("firstPage")){ result = pagination.getFirstPage(); } else{ result=pagination.getJumpPage(pagetype); } } else { result = pagination.getProducts(); } return result; } /** * <p> * </p> * */ //此对象中保存了页面的所有情况,包括多少页等信息 public PaginationBean getPagePagination() { return pagination; } /** * <p> * </p> */ //实例化PaginationBean的构造函数 public void Init(ArrayList result) { this.result = result; pagination = new PaginationBean(result); } } ------------------------------ import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.list.struts.form.ListForm; import com.list.struts.util.Page; import com.list.struts.util.PageBean; import com.list.struts.util.PaginationBean; import com.list.struts.vo.newgetResouce; public class ListAction extends Action { /* * Generated Methods */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { //若提交页面有提交信息,则用listForm获取进行数据库查询 //ListForm listForm = (ListForm) form;// TODO Auto-generated method stub List<PageBean> list = new ArrayList<PageBean>(); newgetResouce newgetresouce = new newgetResouce(); //通过显示页面传递一个pagetype对象和PaginationBean对象 Page page = new Page(request.getParameter("pagetype"),(PaginationBean)request.getSession().getAttribute("page3")); //非第一次进入显示页面 if(!page.isEmpty()){ request.setAttribute("page",page.getPagePagination()); request.setAttribute("list",page.getResult()); return mapping.findForward("suc"); } //获取数据库中所查询的数据的list list = newgetresouce.getlistcount(); //初始化PaginationBean的构造方法 page.Init((ArrayList)list); //保存一个PaginationBean的对象,用于在页面中调用其中的属性,判断页面的跳转 request.setAttribute("page", page.getPagePagination()); //用于其他页面调用PaginationBean的对象 request.getSession().setAttribute("page3", page.getPagePagination()); //保存所要查询的当前页面的list request.setAttribute("list", page.getResult()); //跳转到成功页面 return mapping.findForward("suc"); } } ----------------------------------- <%@ page language="java" contentType="text/html;charset=utf-8" %> <%@ include file="Strutstaglibs.jsp" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <html> <head> <title>分页技术信息显示页面</title> </head> <body bgcolor="green"> <table align="center"> <tr> <th>用户名</th> <th>密 码</th> <th>生 日</th> <th>职 业</th> <th>性 别</th> </tr> <logic:present name = "list"> <logic:iterate id="temp" name ="list"> <tr align="center"> <td><bean:write name="temp" property="userName"/></td> <td><bean:write name="temp" property="pwd"/></td> <td><bean:write name="temp" property="birthday"/></td> <td><bean:write name="temp" property="trade"/></td> <td><bean:write name="temp" property="sex"/></td> </tr> </logic:iterate> </logic:present> <tr> <td colspan="4" align="right" valign="top"> <logic:equal name="page" property="hasfirstPage" value="true"> <html:link page="/list.do?pagetype=firstPage"> <font color=red>首页</font> </html:link> </logic:equal> <logic:equal name="page" property="hasPreviousPage" value="true"> <html:link page="/list.do?pagetype=previousPage"> <font color=red>上一页</font> </html:link> </logic:equal> <logic:equal name="page" property="hasNextPage" value="true"> <html:link page="/list.do?pagetype=nextPage"> <font color="red">下一页</font> </html:link> </logic:equal> <logic:equal name="page" property="haslastPage" value="true"> <html:link page="/list.do?pagetype=lastPage"> <font color="red">末页</font> </html:link> </logic:equal> </td> <td align="center" valign="middle"> <%-- <html:form action="/list.do">跳到第 <html:select property="temp" size="1" onchange="document.forms[0].submit()"> <c:forEach var="pagetype" begin="1" end="${page.totalPages}"> <html:option value="pagetype" ><bean:write name="pagetype" /></html:option> document.forms[0].page.options[${page.currentPage}-1].selected = true; </c:forEach> </html:select>页 </html:form> --%> <form action="./list.do" method="get">跳到第 <select name ="pagetype" onchange="document.forms[0].submit()"> <script language = "JavaScript"> for(i=1;i<=${page.totalPages};i++) document.write("<option value="+i+">"+i+"</option>"); document.forms[0].pagetype.options[${page.currentPage}-1].selected = true; </script> </select>页 </form> </td> </tr> </table> </body> </html>
- 1
- 粉丝: 29
- 资源: 43
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
- 1
- 2
前往页