jsp分頁程式

來源:互聯網
上載者:User


<%@ 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">
</head>
<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>標題</b></td>
<td><b>作者</b></td>
<td><b>類型</b></td>
<td><b>點擊</b></td>
<td><b>加入時間</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="小說";
break;
case(2):
ArticleType="散文";
break;
case(3):
ArticleType="詩歌";
break;
case(4):
ArticleType="隨筆";
break;
}
%>
<tr bgcolor="<%= Color %>">
<td width="300"><a href="viewarticle.jsp?aID=<%= aID %>"><%= aTitle %></a></td>
<td align="center" width="100"><%= aAuthor %></td>
<td align="center" width="50"><%= ArticleType %></td>
<td align="center" width="50"><%= ReadTime %></td>
<td align="center" width="240"><%= InsertTime %></td>
</tr>
<%
cu++;
}
%>
<tr bgcolor="#CCCCCC">
<td colspan="5" align="right" valign="middle">共 <%= allCol %>條記錄 共 <%= allpage %>頁 <% if (cpage>1) { %><a href="article.jsp?pages=<%= cpage-1 %>"><img src="images/prev.gif" border="0"></a><% } if (cpage<allpage) { %><a href="article.jsp?pages=<%= cpage+1 %>"><img src="images/next.gif" border="0"></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>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.