JSP uses JSTL to implement page-flipping instance code _jsp programming

Source: Internet
Author: User
Tags prev

Use Jstl to show that the code looks more neat than the JSP, and makes the code less

Copy Code 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"%>
<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 (Please enter the number of pages you want to jump to!) ");
else if (isNaN (page)) {
Alert (Please enter a valid number of pages!) ");
} else {
Document.forms[0].submit ();
}
}
</script>
<body>
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}"/> Strip
<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>
&LT;TD height= "align=" "Center" bgcolor= "#FFFFFF" >
<c:out value= "${result.pagenum} page/"/>
<c:out value= "Total ${result.totalpage} page"/>
<c:out value= "Total ${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 | end"/>
</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} ' > End </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>

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.