A simple JSP paging code __jsp

Source: Internet
Author: User
Tags stmt

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ page language= "java" import= "Java.sql.connection,java.sql.statement,java.sql.resultset"%>
<jsp:directive.page import= "Java.sql.DriverManager;" />
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<body>
<%
Connection Con=null;
Loading Oracle jdbc Thin drivers
Class.forName ("Oracle.jdbc.driver.OracleDriver");
Oracle Thin JDBC URL
String url= "JDBC:ORACLE:THIN:@192.168.10.2:1521:ORA10";
con = drivermanager.getconnection (URL, "TRSPORTALV6", "TRSPORTALV6");
Statement stmt=con.createstatement ();
String sql= "SELECT COUNT (*) from Wcmmetatablexwlw_zzh";
ResultSet rs=stmt.executequery (SQL);
int jumppage=1;//Jump Page
int pagenum=1;//Current Page
int pagesize=3;//per page size
int countpage=0;//Total Pages
Total Records of int countrecord=0;//
Total number of records
if (Rs.next ()) {
Countrecord=rs.getint (1);
}
Total pages
if (countrecord% pageSize = = 0) {
Countpage = countrecord/pagesize;
}else{
Countpage = countrecord/pagesize+1;
}
String strpage=request.getparameter ("Pagenum");
String strjump=request.getparameter ("Jumppage");
if (strpage==null) {
pagenum=1;//if not, show the first page
}else{
Pagenum=integer.parseint (strpage);
if (pagenum<1) {
Pagenum=1;
}
}
To judge a jump page
if (strjump!=null) {
Pagenum=integer.parseint (Strjump);
if (pagenum<1) {
Pagenum=1;
}
if (pagenum>countpage) {
Pagenum=countpage;
}
}
int startpage= (pageNum-1) *pagesize+1;
int endpage= (pagenum) *pagesize;

This SQL statement is important and basically uses Oracle's rownum to implement pagination.
Sql= "SELECT * from" (select T.*,rownum r from Wcmmetatablexwlw_zzh T) where R between "+startpage+" and "+endpage+" ";
Rs=stmt.executequery (SQL);
while (Rs.next ()) {
%>
<table>
<tr><td><%=rs.getstring ("Cruser")%></td><td><%=rs.getstring ("CRTIME")%> </td></tr>
</table>
<%}%>
<table>
<form name= "name" action= "test.jsp" >
<tr>
<td> a total of <%=countRecord%> records </td>
<td> <a href= "test.jsp?pagenum=<%=pagenum%>" ><%=pageNum%></a> page </td>
<td> Total <%=countPage%> page </a></td>
<td><a href= "test.jsp?pagenum=0" > Home </a></td>
<td><%if (pagenum>1) {%><a href= "test.jsp?pagenum=<%=pagenum-1%>" > Prev </a><%}% ></td>
<td><%if (pagenum<countpage) {%><a href= "test.jsp?pagenum=<%=pagenum+1%>" > next page </a> <%}%></td>
<td><a href= "test.jsp?pagenum=<%=countpage%>" > Last </a></td>
<td> go to <input type= "text" name= "Jumppage" style= "width:15px" > Page <input type= "submit" value= "Jump" >< /TD>
</tr>
</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.