使用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>