js| Paging//author tar (bigangell@yesky.com)
You can copy the code in any copy, but please add the above author information
If you have any questions, please contact me.
Effect Please see http://210.77.144.64/kk/java/java/article.jsp
<%@ page import= "java.sql.*"%>
<%@ page import= "java.io.*"%>
<%@ page import= "Java.util". * "%>
<jsp:usebean id=" sqlconn "scope=" page "class=" Kk.database.sqlconn "/>
<%! String Atitle,aauthor,atype,articletype,inserttime,color; %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> articlelist</title>
<meta name= "generator" content= "jBuilder3.5 && jEdit1.0" >
<meta Name= "Author" content= "Bigangell" >
<meta name= "Keywords" content= "java,servlet,jsp,beans,php" >
<meta name= "Description" content= "A Pure world for Programming Include C/c++,java" >
<meta http-equiv= " Content-type "content=" text/html; charset=gb2312 ">
<link rel=" stylesheet "href=" Style.css ">
<body bgcolor= "#FFFFFF" >
<table width= "760" border= "0" cellspacing= "0" cellpadding= "0" align= "center" >
<tr>
<td>
<table width= "750" border= "0" cellspacing= "2" cellpadding= "2" align= "Center" >
<TR align= "center" >
<td> </td>
</tr>
<tr>
<td>
<table width= "740" 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> type </b></td>
<td><b> Click </b></td>
<td><b> Add Time </b></td>
</tr>
<%
int i;
int ipage=10;
int allpage;
int pages;
int cpage=1;
int spage;
Java.lang.String Sql,pagesql;
Java.sql.ResultSet rs,pagers;
Pagesql = "SELECT count (a_id) as a from article";
pagers = Sqlconn.executequery (pagesql);
int allcol = Pagers.getint ("A");
Allpage = (int) Math.ceil (allcol + ipage-1)/ipage);
if (Request.getparameter ("pages") ==null) {
Pages=1;
} else {
pages = new Integer (Request.getparameter ("pages")). Intvalue ();
}
if (pages > allpage//pages = 0) {
Cpage = 1;
} else {
cpage = pages;
}
Spage= (cpage-1) *ipage;
sql = "Select A_id,a_title,a_author,aid,a_time,a_readtime,sid from article ORDER by a_id desc LIMIT" + spage + "," + ipage;
rs = sqlconn.executequery (SQL);
int cu=1;
while (Rs.next ()) {
int AID = Rs.getint ("a_id");
Atitle = rs.getstring ("A_title");
Aauthor = rs.getstring ("A_author");
int Articletypeid = Rs.getint ("AID");
int readtime = Rs.getint ("A_readtime");
Inserttime = rs.getstring ("A_time");
if (cu% 2 = 0) {color= "#DBECFD";}
else {color= "#C6E1FD";}
Switch (Articletypeid) {
Case (1):
Articletype= "novel";
Break
Case (2):
Articletype= "prose";
Break
Case (3):
Articletype= "Poetry";
Break
Case (4):
Articletype= "Essays";
Break
}
%>
<tr bgcolor= "<%= Color%>" >
<TD width= "><a" href= "viewarticle.jsp?aid=<%= aID%>" ><%= atitle
<TD align= "center" width= "><%= aauthor%></td>
<TD align= "center" width= "><%= articletype%></td>
<TD align= "center" width= "><%= readtime%></td>
<TD align= "center" width= "><%= inserttime%></td>
</tr>
<%
cu++;
}
%>
<tr bgcolor= "#CCCCCC" >
<TD colspan= "5" align= "right" valign= "middle" > Total <%= allcol%> Records total <%= allpage%> page <% if (cpage>1) {%><a href= "article.jsp?pages=<%= cpage-1%>" ></a><%} if (cpage<allpage) {%><a href=" article.jsp?pages=<%= cpage+1% > "></a><%}%>/<% for (i=1;i<=allpage;i++) {if (i!= pages) {%><a href= "article.jsp?pages=<%= i%>" ><%= i%></a> <%}}%></td> ;
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>