JSP uses JSTL to implement the paging instance code

Source: Internet
Author: User
Tags foreach prev

  This article mainly introduces the JSP uses JSTL to implement the paging instance code, has the need friend may refer to the

Using JSTL to display the code is more neat than using JSP, but also makes the code appear less     code as follows: <% @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> search </title> <script type=" Text/javascript ">  function validate1 () {& nbsp var page = Document.forms[0].page.value;   if (page.length <= 0) {   alert ("Please enter the number of pages to jump to!") ");  } else if (isNaN (page) {   alert ("Please enter a valid number of pages!") ");  } else {   document.forms[0].submit ();  }   </script> </head> <body> &nbsp ; Retrieval time: <c:out value= "${result.costtime}"/>   Total records: <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>   title: <c:out value=" <a href= ' servletdetail?rid=${ Current.rowid} ' >${current.title}</a> ' escapexml= ' false ' ></c:out>   <br> Date: <c:out Value= "${current.date}"/>  </c:forEach>  <table width= "100%" border= "0" align= "center" cellpadding= "0"   cellspacing= "0" bgcolor= "#8C8C8C" >   <tr>    <td height= "align=" Center "bgcolor=" #FFFFFF ">    <c:out value=" ${result.pagenum} page/"/>    <c:out value=" Total ${result.totalpage} page "/>    <c:out value=" ${result.total} records "/>    <c:if test=" ${ RESULT.PAGENUM<2} ">     <c:out value=" Home | prev "/>    </c:if>    <c:if Test= "${result.pagenum>=2}" >     <c:out value= "<a href=" servletsearch?page=${1}&keyword=${keyword} ' > Home </a> ' escapexml= ' false '/>     <c:out value= ' <a href= ' Servletsearch?page=${result.pagenum-1}&keyword=${keyword} ' > Prev </a> ' escapexml= ' false '/>    </c:if>    <c:out value= "|" />    <c:if test= "${(result.totalpage-result.pagenum) <1}" >     <c:out value= "Next page | Last "/>    </c:if>    <c:if test=" ${(result.totalpage-result.pagenum) >=1} ">     <c:out value= "<a href= ' Servletsearch?page=${result.pagenum+1}&keyword=${keyword} ' > next page </a> "escapexml=" false "/>     <c:out value=" <a href= ' Servletsearch?page=${result.totalpage} &keyword=${keyword} ' > Last </a> ' escapexml= ' false '/>    </c:if>    <form action= "Servletsearch" method= "post" >     <input type= "text" name= "page" ><input type= "hidden" Name= "KeyWord" Value=${keyword}> &nbsp   <input type= "button" value= "Jump to" onclick= "validate1 ()" >    </form>  </table> </body> </html>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.