JSP Page Paging Program

Source: Internet
Author: User

<%@ page import= "java.sql.*"%>
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%! String au_id,au_lname,au_fname,phone,address,city,state;%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE>ArticleList</TITLE>
<link rel= "stylesheet" href= "Style.css" >
<body bgcolor= "#FFFFFF" >
<table width= "834" border= "0" cellspacing= "0" cellpadding= "0" align= "center" >
<tr>
&LT;TD width= "834" >
<table width= "border=" 0 "cellspacing=" 2 "cellpadding=" 2 "align=" Center ">
&LT;TR align= "center" >
&LT;TD width= "792" >&nbsp;</td>
</tr>
<tr>
<td>
<table width= "794" border= "0" cellspacing= "1" cellpadding= "1" align= "Center" >
&LT;TR align= "center" bgcolor= "#CCCCCC" >
<td><b> title </b></td>
<td><b> author </b></td>
<td><b> Types </b></td>
<td><b> Click </b></td>
&LT;TD width= ><b> Join </b></td>
</tr>
<%
int i;
int ipage=5; Pages
int allpage; Page numbers
int pages; The number of pages accepted
int cpage=1; When you are in front of
int spage; Start Page
int allcol=0;
Vector V=null;
Data Library Connection sounds
Connection Conn=null;
Java.lang.String Sql,pagesql;
Java.sql.ResultSet rs,pagers;
Statement Statement=null;
String kmsdb= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=db_szscz";
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = Drivermanager.getconnection (Kmsdb, "sa", "");

Pagesql = "Select COUNT (*) from tb_news";
Take the total number of articles
statement = Conn.createstatement ();
pagers = Statement.executequery (pagesql);
while (Pagers.next ())
{
Allcol = Pagers.getint (1);
System.out.println (Allcol);
}

Get the number of pages
Allpage = (int) Math.ceil (allcol + ipage-1)/ipage);
Whether the number of pages is empty
if (Request.getparameter ("pages") ==null) {
Pages=1;
} else {
pages = new Integer (Request.getparameter ("pages")). Intvalue ();
SYSTEM.OUT.PRINTLN (pages);
}
To judge the front page
if (pages > Allpage | | pages = 0)
{cpage = 1;}
Else
{
cpage = pages;
}
The starting page is judged
sql = ' Select top ' +ipage+ ' news_id,news_title,news_author,news_content from tb_news where news_id ' not in ' (select Top + C page-1) *ipage+ "news_id from Tb_news ORDER BY news_id Desc" ORDER BY news_id Desc ";
rs = statement.executequery (SQL);
while (Rs.next ())
{
Au_id=rs.getstring ("news_id");
Au_lname=rs.getstring ("News_title");
Au_fname=rs.getstring ("News_author");
%>
&LT;TD width= "175" ><%= au_id%></a></td>
&LT;TD width= "175" ><%= au_lname%></a></td>
&LT;TD width= "175" ><%= phone%></a></td>
&LT;TD width= "171" ><%= address%></a></td>
</tr>
<%
}%>
<tr bgcolor= "#CCCCCC" >
&LT;TD colspan= "5" align= "right" valign= "middle" > A total of <%= allcol%> a total <%= allpage%> page <% if (cpage>1) {%><a href= "a.jsp?pages=<%= cpage-1%>" >pre</a><%} if (cpage<allpage) {%><a href= "a. jsp?pages=<%= cpage+1%> ">next</a><%}%>/<% for (i=1;i<=allpage;i++) {if (I!= pages) {%&gt ; <a href= "a.jsp?pages=<%= i%>" ><%= I%></a>&nbsp;<%}}%></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</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.