下面说说表现层,代码如下:
xml 代码
- <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
- <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
- <%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
- <%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <script type="text/javascript">
js 代码
- //修改每页显示的记录数
- function changePageSize(){
- document.forms[0].submit();
- }
- //直接跳转到某个页面
- function jumpPage(){
- var page = document.getElementById('page').value;
- var offset = (page -1 )*document.getElementsByName('pageDisplay')[0].value;
- document.location.href('check.do?pager.offset='+offset+'&page='+page);
- }
xml 代码
- </script>
- <html>
- <head>
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <body>
- <!-- 查询条件部分 -->
- <html:form action="/check.do" method="post">
- <table>
- <tr>
- <td>
- 内容:
- </td>
- </tr>
- <tr>
- <td>
- <html:text property="content" />
- </td>
- </tr>
- <tr>
- <td>
- <input type="submit" />
- </td>
- </tr>
- </table>
- <!-- 数据显示部分 -->
- <c:if test="${result != null}">
- <pg:pager items="${count}" maxPageItems="${pageSize}" index="center" maxIndexPages="5" export="offset,currentPageNumber=pageNumber" scope="request" url="check.do">
- 数据:<br />
- <table width="100%" border="1">
- <c:forEach items="${result}" var="subpage">
- <tr>
- <td>
- <c:out value="${subpage.content}"></c:out>
- </td>
- <td>
- <c:out value="${subpage.intValue}"></c:out>
- </td>
- </tr>
- </c:forEach>
- </table>
- <pg:index>
- 第
- <select id="page" onchange="jumpPage();">
- <pg:pages>
- <c:if test="${pageNumber == currentPageNumber}">
- <option value="${pageNumber}" selected="selected" >${pageNumber}</option>
- </c:if>
- <c:if test="${pageNumber != currentPageNumber}">
- <option value="${pageNumber}" >${pageNumber}</option>
- </c:if>
- </pg:pages>
- </select>
- 页
- 共<c:out value="${totalPage }"></c:out>页
- <pg:first>
- <a href="<%= pageUrl %>&page=${pageNumber}">首页</a>
- </pg:first>
- <pg:prev>
- <a href="<%= pageUrl %>&page=${pageNumber}">上一页</a>
- </pg:prev>
- <pg:next>
- <a href="<%= pageUrl %>&page=${pageNumber }">下一页</a>
- </pg:next>
- <pg:last>
- <a href="<%= pageUrl %>&page=${pageNumber }">末页</a>
- </pg:last>
- 共${count}条记录
- 每页显示
- <html:text property="pageDisplay" onchange="changePageSize();"/>
- 条记录
- </pg:index>
- </pg:pager>
- </c:if>
- </html:form>
- </body>
- </html>