Jsp uses jstl to implement paging instance code

Source: Internet
Author: User

Displaying with jstl is more neat and less code than displaying with jsp

Copy codeThe Code is 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 (){
Var page = document. forms [0]. page. value;
If (page. length <= 0 ){
Alert ("Enter the number of pages to jump! ");
} Else if (isNaN (page )){
Alert ("enter a valid number of pages! ");
} Else {
Document. forms [0]. submit ();
}
}
</Script>
</Head>
<Body>
Retrieval time: <c: out value = "$ {Result. costtime}"/>
Total number of records: <c: out value = "$ {Result. total} <br>" escapeXml = "false"/>
<C: forEach items = "$ {Result. article}" var = "current" varStatus = "status">
<Br> Article <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 = "22" align = "center" bgcolor = "# FFFFFF">
<C: out value = "{Result. pageNum} page/"/>
<C: out value = "$ {Result. totalPage} page in total"/>
<C: out value = "$ {Result. total} records in total"/>
<C: if test = "$ {Result. pageNum <2}">
<C: out value = "homepage | previous page"/>
</C: if>
<C: if test = "$ {Result. pageNum >=2}">
<C: out value = "<a href = 'servletsearch? Page =$ {1} & keyWord =$ {keyWord} '> homepage </a> "escapeXml =" false "/>
<C: out value = "<a href = 'servletsearch? Page =$ {Result. pageNum-1} & keyWord =$ {keyWord} '> previous page </a> "escapeXml =" false "/>
</C: if>
<C: out value = "|"/>
<C: if test = "$ {(Result. totalPage-Result.pageNum) <1}">
<C: out value = "next page | last page"/>
</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 page </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 = "Jump to" onClick = "validate1 ()">
</Form>
</Table>
</Body>
</Html>

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.