這篇文章主要介紹了jsp 使用jstl實現翻頁實例代碼,有需要的朋友可以參考一下
使用jstl進行顯示相對使用jsp來說代碼更顯得整齊,也使代碼量顯得較少 代碼如下: <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri = "http://java.sun.com/jsp/jstl/core"%> <%@page import="java.util.List"%> <%@page session="true"%> <%@page errorPage="error.jsp"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>檢索</title> <script type="text/javascript"> function validate1() { var page = document.forms[0].page.value; if (page.length <= 0) { alert("請輸入要跳轉到的頁數!"); } else if (isNaN(page)) { alert("請輸入有效的頁數!"); } else { document.forms[0].submit(); } } </script> </head> <body> 檢索時間:<c:out value="${Result.costtime }" /> 記錄總數:<c:out value="${Result.total }<br>" escapeXml="false"/> <c:forEach items="${Result.article}" var="current" varStatus="status"> <br>第<c:out value="${status.count+(Result.pageNum-1)*20}"/>條 <br> 標題:<c:out value="<a href='servletDetail?rID=${current.rowid}'>${current.title}</a>" escapeXml="false"></c:out> <br>日期:<c:out value="${current.date}"/> </c:forEach> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#8C8C8C"> <tr> <td height="22" align="center" bgcolor="#FFFFFF"> <c:out value="第${Result.pageNum }頁/"/> <c:out value="共${Result.totalPage }頁"/> <c:out value="共${Result.total }條記錄"/> <c:if test="${Result.pageNum<2 }"> <c:out value="首頁|上一頁"/> </c:if> <c:if test="${Result.pageNum>=2 }"> <c:out value="<a href='servletSearch?page=${1}&keyWord=${keyWord }'>首頁</a>" escapeXml="false"/> <c:out value="<a href='servletSearch?page=${Result.pageNum-1}&keyWord=${keyWord }'>上一頁</a>" escapeXml="false"/> </c:if> <c:out value="|"/> <c:if test="${(Result.totalPage-Result.pageNum)<1 }"> <c:out value="下一頁|尾頁"/> </c:if> <c:if test="${(Result.totalPage-Result.pageNum)>=1 }"> <c:out value="<a href='servletSearch?page=${Result.pageNum+1}&keyWord=${keyWord}'>下一頁</a>" escapeXml="false"/> <c:out value="<a href='servletSearch?page=${Result.totalPage}&keyWord=${keyWord}'>尾頁</a>" escapeXml="false"/> </c:if> <form action="servletSearch" method="post"> <input type="text" name="page"><input type="hidden" name="keyWord" value=${keyWord}> <input type="button" value="跳轉到" onClick="validate1()"> </form> </table> </body> </html>