Chinaunix首页 | 论坛 | 博客
  • 博客访问: 398114
  • 博文数量: 93
  • 博客积分: 3006
  • 博客等级: 少校
  • 技术积分: 998
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-02 17:23
文章分类

全部博文(93)

文章存档

2011年(12)

2010年(38)

2009年(20)

2008年(23)

分类: 系统运维

2011-05-13 09:35:14

根据前面的一个代码Page和PaginationHelper类可以查出第几页的数据返回一个List
Servlet层:
  1. // 分析当前页码
  2.         String pageString=req.getParameter("page");
  3.         if(pageString == null || pageString.length() == 0) {
  4.         pageString = "1";
  5.         }
  6.         int currentPage= 0 ;
  7.         try {
  8.         currentPage = Integer.parseInt(pageString);// 当前页码
  9.         } catch(Exception e) {}
  10.         if(currentPage == 0) {
  11.             currentPage = 1;
  12.         }
  13.         int pageSize = 30;//每页显示的数据数
  14.         
  15.         PaginationHelper<EipSms> ph = new PaginationHelper<EipSms>();
  16.      List<EipSms> ls=new ArrayList<EipSms>();
  17.      Page<EipSms> p=ph.fetchPage(
  18.                 jdbc,
  19.                 "SELECT COUNT(*) FROM EIP_SMS WHERE CUSERID=? AND STATUS='1'",
  20.                 "SELECT PK_EIP_SMS,RUSER,CONTENT,CTIME FROM EIP_SMS WHERE CUSERID=? AND STATUS='1'",
  21.                 new Object[]{pageUser.getUserID()},
  22.                 currentPage,
  23.                 pageSize,
  24.                 new ParameterizedRowMapper<EipSms>() {
  25.                     public EipSms mapRow(ResultSet rs, int i) throws SQLException {
  26.                         return new EipSms(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4));
  27.                     }
  28.                 }
  29.         );
  30.      ls=p.getPageItems();
  31.      req.getSession().setAttribute("ls",ls);// 保存列表
  32.      req.getSession().setAttribute("totalPage", p.getPagesAvailable());// 保存总页数
  33.      req.getSession().setAttribute("currentPage", currentPage);// 保存当前页码
  34.     
  35.      res.sendRedirect("resources/sms/sms_draft.jsp");

表现层:
  1. <td>
  2.                 <%-- 输出页面跳转代码, 分链接和静态文字两种 --%>
  3.                 <c:if test="${currentPage > 1}">
  4.                 [ <a href="${pageContext.request.contextPath}/showsms?type=draft&page=${currentPage-1}">上一页</a> ]
  5.                 </c:if>
  6.                 <c:if test="${currentPage <= 1}">
  7.                 [ 上一页 ]
  8.                 </c:if>
  9.                 <c:if test="${currentPage < totalPage}">
  10.                 [ <a href="${pageContext.request.contextPath}/showsms?type=draft&page=${currentPage+1}">下一页</a> ]
  11.                 </c:if>
  12.                 <c:if test="${currentPage >= totalPage}">
  13.                 [ 下一页 ]
  14.                 </c:if>
  15.                 <%-- 输出 JavaScript 跳转代码 --%>
  16.                 <script>
  17.                 // 页面跳转函数
  18.                 // 参数: 包含页码的表单元素,例如输入框,下拉框等
  19.                 function jumpPage(input) {
  20.                 // 页码相同就不做跳转
  21.                 if(input.value == ${currentPage}) {
  22.                     return;
  23.                 }
  24.                 var newUrl = "${pageContext.request.contextPath}/showsms?type=draft&page=" + input.value;
  25.                     document.location = newUrl;
  26.                 }
  27.                 </script>
  28.                 转到
  29.                 
  30.                 <select onchange='jumpPage(this);'>
  31.                 <c:forEach var="i" begin="1" end="${totalPage}">
  32.                 <option value="${i}"
  33.                 <c:if test="${currentPage == i}">
  34.                 selected
  35.                 </c:if>
  36.                 >第${i}</option>
  37.                 </c:forEach>
  38.                 </select>
  39.                 </td>



  1. //循环输出list
  2. <c:forEach items="${ls}" var="sms" >
  3.                     <tr>
  4.                     <td></td>
  5.                     <td><input type="checkbox" name="$$SelectDoc" value="${sms.pk_eip_sms}"></td>
  6.                     <td><font size="2"><a href="" target="_blank">${sms.content}</a></font></td>
  7.                     <td><font size="2">${sms.ctime}</font></td>
  8.                     <td>${sms.ruser}</td>
  9.                     </tr>
  10.                 </c:forEach>
阅读(2850) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~