<%@ 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>
<TD width= "834" >
<table width= "border=" 0 "cellspacing=" 2 "cellpadding=" 2 "align=" Center ">
<TR align= "center" >
<TD width= "792" > </td>
</tr>
<tr>
<td>
<table width= "794" border= "0" cellspacing= "1" cellpadding= "1" align= "Center" >
<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>
<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");
%>
<TD width= "175" ><%= au_id%></a></td>
<TD width= "175" ><%= au_lname%></a></td>
<TD width= "175" ><%= phone%></a></td>
<TD width= "171" ><%= address%></a></td>
</tr>
<%
}%>
<tr bgcolor= "#CCCCCC" >
<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) {%> ; <a href= "a.jsp?pages=<%= i%>" ><%= I%></a> <%}}%></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>