Today, I read a lot of paging programs, which are just too complicated. I can't write more simply, so I spent more than an hour writing a maple leaf program of jstl + EL + JSP. The code is quite simple and easy to understand, it is also easy to modify to your own paging program. First paste the code to see:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@include file="inner/jstl.jsp"%><%@include file="inner/DataSource.jsp"%><% if (request.getParameter("currentPage") == null) { pageContext.setAttribute("currentPage", new Integer(0)); } else { pageContext.setAttribute("currentPage", request .getParameter("currentPage")); }%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
---------------------------------------------------
Jstl. jsp page:
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "C" %> <% @ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "FMT" %> <% @ taglib uri = "http://java.sun.com/jsp/jstl/functions "prefix =" functions "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/ SQL "prefix =" SQL "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/xml "prefix =" X "%> datasource. JSP page: <SQL: setdatasource url = "JDBC: mysql: // localhost: 3306/News" driver = "com. mySQL. JDBC. driver "user =" *** "Password =" ***** "/>
The following describes some variables:
Suppose you have 26 records and you want to display 5 records on each page, you need 6 pages.
Currentpage is any page in Sign 6, which is achieved through hyperlinks.
Resultnum is all 26 records.
Perpagenum number of records to be displayed on each page
OK, you can. You can modify the database and run it to see the effect.