熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

高效簡單的jsp分頁代碼

2022-06-13   來源: JSP教程 
<%@ page import="javasql*javaio*javautil*" %>
<%@ page language="java" pageEncoding="Big" %>
<%! String au_idau_lnameau_fnamephoneaddresscitystate;%>
<!DOCTYPE HTML PUBLIC "//WC//DTD HTML Transitional//EN">
<HTML>
<HEAD>
<TITLE>ArticleList</TITLE>
<link rel="stylesheet" href="stylecss">
</head>
<body bgcolor="#FFFFFF"> <table width="" border="" cellspacing="" cellpadding="" align="center">
<tr>
<td>
<table width="" border="" cellspacing="" cellpadding="" align="center">
<tr align="center">
<td>&nbsp;</td>
</tr>
<tr>
<td>
<table width="" border="" cellspacing="" cellpadding="" align="center">
<tr align="center" bgcolor="#CCCCCC">
<td><b>標題</b></td>
<td><b>作者</b></td>
<td><b>類型</b></td>
<td><b>點擊</b></td>
<td><b>加入時間</b></td>
</tr>
<%
int i;
int ipage=; //分頁單位
int allpage; //總頁數
int pages; //接受的頁碼變數
int cpage=; //當前頁
int spage; //開始頁
int allCol=;
Vector v=null; //資料庫連接聲明
Connection conn=null;
 javalangString sqlpagesql;
 javasqlResultSet rspagers;
 Statement statement=null;
 String kmsdb="jdbc:microsoft:sqlserver://:;DatabaseName=DBName";
 ClassforName("commicrosoftjdbcsqlserverSQLServerDriver");
    conn = DriverManagergetConnection(kmsdb "user" "pwd");
 
 pagesql = "SELECT COUNT(*) FROM  Authors"; //取總文章數
statement = conncreateStatement();
pagers = statementexecuteQuery(pagesql);
 while(pagersnext())
  {
  allCol = pagersgetInt();
  Systemoutprintln(allCol);   }
 
//獲得總頁面數
allpage = (int)Mathceil((allCol + ipage) / ipage);
//判斷參數pages是否空
if (requestgetParameter("pages")==null) {
pages=;
} else {
pages = new Integer(requestgetParameter("pages"))intValue();
Systemoutprintln(pages);
}
//判斷當前頁
if(pages > allpage || pages == )
{cpage = ;}
else
{
cpage = pages;
}
//判斷起始頁
sql = "select Top "+ipage+" au_idau_lnameau_fnameaddressphone from authors where au_id not in (select top "+(cpage)*ipage+" au_id from authors order by au_id desc)order by au_id desc";
rs = statementexecuteQuery(sql);
while (rsnext())
{
 au_id=rsgetString("au_id");
 au_lname=rsgetString("au_lname");
 au_fname=rsgetString("au_fname");
 phone=rsgetString("phone");
 address=rsgetString("address"); %> 
 <td width=""><%= au_id %></a></td>
 <td width=""><%= au_lname %></a></td>
 <td width=""><%= au_fname %></a></td>
 <td width=""><%= phone %></a></td>
 <td width=""><%= address %></a></td>
</tr>
<%    
}%>
<tr bgcolor="#CCCCCC">
<td colspan="" align="right" valign="middle">共 <%= allCol %>條記錄 共 <%= allpage %>頁 <% if (cpage>) { %><a href="fyjsp?pages=<%= cpage %>"><img src="% } if (cpage<allpage) { %><a href="fyjsp?pages=<%= cpage+ %>"><img src="% } %> / <% for (i=;i<=allpage;i++) { if (i != pages) {%><a href="fyjsp?pages=<%= i %>"><%= i %></a>&nbsp;<% }} %></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20539.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.