jspページング


//more.jsp

<%@ page language="java"
	import="java.util.*,java.sql.*,com.apache.log.util.*,java.sql.ResultSet,java.text.SimpleDateFormat"
	pageEncoding="utf-8"%>
<%@ page import="com.zj.comm.util.Common"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<wml>
<head>
	<meta http-equiv="Cache-Control" content="max-age=0" />
	<meta http-equiv="Cache-Control" content="no-cache" />
</head>
<card id="mobile" title="jsp">
<p>
<a href="index.jsp">    </a>》    
<br/>
<%
int pn=0;
int pagesize=10;
if (request.getParameter("pn") != null)
					pn = Integer.parseInt(request.getParameter("pn"));
	Connection conn = null;
	Connection connl = null;
		PreparedStatement ps = null;
		PreparedStatement psl = null;
		ResultSet rs = null;
		ResultSet rsl = null;
		try {
				conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","zshz_db","zshz_db");
				String sql = "select * from (select t.*,rownum rn from( select * from hd_spring  where sign='msg'order by createtime desc)t  where rownum<="+pagesize*(pn+1)+")where rn>"+pagesize*pn+"";
				//out.print(sql);
				ps = conn.prepareStatement(sql);
				ps.executeUpdate();
				rs=ps.executeQuery();
				while (rs.next()) {%>
				-<%=rs.getString("mobile") %>:
				<%=rs.getString("message") %>
				<br/>
				<%	
				}%>
				<%
				connl = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","system","orcl");
				String sqll="select count(message) from hd_spring where sign='msg'";
				psl=connl.prepareStatement(sqll);
			//	psl.executeUpdate();
				rsl=psl.executeQuery();
				if(rsl.next()){
				out.print("<a href='more.jsp?pn="+(pn-1)+"'>   </a>"+"|");
				out.print("<a href='more.jsp?pn="+(pn+1)+"'>   </a>");
			}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (conn != null) {
					conn.close();
				}
			}
 %>
<br/>
</p>
</card>
</wml>

JSPページング(うっかりネットで見つけた)
//page.jsp


<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Insert title here</title>
	</head>
	<body>

		<%
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/data";
			Connection con = DriverManager.getConnection(url, "root", "root");
			Statement stmt = con.createStatement(
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			int intPageCount;//   
			int intRowCount;//   
			int intPageSize;//       
			int intPage;//   
			int intNext;//   
			int intPrev;//   
			int i;
			String strPage;
			strPage = request.getParameter("Page");
			if (strPage == null) {
				intPage = 1;
			} else {
				intPage = Integer.parseInt(strPage);
			}
			String sql = "select * from authors";
			ResultSet rs = stmt.executeQuery(sql);
			rs.last();
			intRowCount = rs.getRow();
			intPageSize = 5;
			intPageCount = (intRowCount + intPageSize - 1) / intPageSize;
			if (intPage > intPageCount) {
				intPage = intPageCount;
			}
			if (intRowCount < intPageSize) {
				intPage = 1;
			}
			if (intPage < 0) {
				intPage = 1;
			}
			;
			i = 0;
			if (intRowCount > 0) {
				rs.absolute((intPage - 1) * intPageSize + 1);
				while (i < intPageSize && !rs.isAfterLast()) {
					out.print(rs.getString("phone") + " ----   "+"    ");
					out.print(rs.getString("address") + " ----   ");
					out.print(rs.getString("au_id") + "<br>");
					rs.next();
					i++;
				}
				rs.close();
				stmt.close();
			}
			intNext = intPage + 1;
			if (intNext > intPageCount) {
				intNext = intPageCount;
			}
			intPrev = intPage - 1;
			if (intPrev < 1) {
				intPrev = 1;
			}
		%>
		 
		<%=intRowCount%>
		    
		<%=intPageCount%>
		      
		<%=intPageSize%>
		   
		<a href="page.jsp?Page=<%=intNext%>">intNext</a>
		<a href="page.jsp?Page=<%=intPrev%>">intPrev</a>



	</body>
</html>