萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> jsp編程 >> jsp分頁顯示完整實例

jsp分頁顯示完整實例

 這篇文章主要介紹了jsp分頁顯示完整實例,以文章管理頁面為例詳細分析了jsp的分頁顯示實現技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了jsp分頁顯示的實現方法。分享給大家供大家參考。

具體實現方法如下:

代碼如下: <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@include file ="../inc/ChkPwd.jsp"%>
<%@include file="../DB.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文章管理</title>
<link href="Style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<table width="98%" height="77%" border="0" cellpadding="0" cellspacing="0">
<tr class="STYLE1">
<td width="100%" height="26" background="images/admin_bg_1.gif"><strong><font color="#FFFFFF">--<span class="STYLE1">內容管理</span></font></strong></td>
</tr>
<tr>
<td colspan="10">
</td>
</tr>

<tr class="title">
<td height="25" background="images/admin_bg_1.gif" class="t2">|
<%
String op;
String ID = request.getParameter("id");
op = request.getParameter("op");
if(op==null){
op = "my";
}
if (op.equals("del") && ID!=null){
String bbb = new String(request.getParameter("BigClassName").getBytes("iso8859_1"));
Statement stmt_ChannelDEL=conn.createStatement();
String Sqldel="delete from hl_news where id=" + ID;
int shan=stmt_ChannelDEL.executeUpdate(Sqldel);
if (shan>0)
{
out.print("<script type="text/javascript"> alert("已成功刪除!"); window.location.href='Hanye_Manages.jsp?BigClassName="+bbb+"'; </script>");
}
stmt_ChannelDEL.close();
return ;
}
Statement stmtA=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SqlA="Select * from hl_smallclass WHERE bigname='行業新聞' order by id asc";
ResultSet RsA=stmtA.executeQuery(SqlA);
while (RsA.next()) {

%>
<a class='t2' href='Hanye_Manages.jsp?modi=新聞&BigClassName=<%=RsA.getString("smallname")%>'><%=RsA.getString("smallname")%></a> |
<%
}
RsA.close(); //關閉記錄集對象
stmtA.close(); //關閉語句對象
%>
</td>
</tr>

<tr>
<td height="20"></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#ECF5FF">

<form name="form2" action="list.asp?action=delall&modi=新聞" method="post">
<table width="100%" cellpadding="3" cellspacing="2" bgcolor="#FFFFFF" style="word-break:break-all">
<tr class="t2">
<td width="32" height="28" align="center" background="images/admin_bg_1.gif" bgcolor="#BBDAFF" class="STYLE1" >ID</td>

<td width="80" align="center" background="images/admin_bg_1.gif" bgcolor="#BBDAFF" class="STYLE1" >新聞大類</td>

<td width="88" align="center" background="images/admin_bg_1.gif" bgcolor="#BBDAFF" class="STYLE1" >新聞小類</td>

<td width="291" align="center" background="images/admin_bg_1.gif" bgcolor="#BBDAFF" class="STYLE1" style="word-break:break-all" >新聞標題</td>

<td width="179" align="center" background="images/admin_bg_1.gif" bgcolor="#BBDAFF" class="STYLE1" >新聞圖片</td>

<td width="76" align="center" background="images/admin_bg_1.gif" bgcolor="#BBDAFF" class="STYLE1" >發布時間</td>

<td width="64" align="center" background="images/admin_bg_1.gif" bgcolor="#BBDAFF" class="STYLE1">操作</td>
</tr>
<%
int pageSize=10; //每頁顯示的文章數
int showPage=1; //當前頁面顯示的頁號
int recCount=0; //ResultSet中的文章總數
int pageCount=0; //分頁後的總頁數
String SqlArticle;
String toPage = request.getParameter("page");
String bgname = new String(request.getParameter("BigClassName").getBytes("iso8859_1"));
Statement stmt_Article=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
SqlArticle="Select * from hl_news where smallname='"+bgname+"' order by ID DESC";
ResultSet RsArticle=stmt_Article.executeQuery(SqlArticle);
if(RsArticle.next()) {
RsArticle.last();//指針飛到最後
recCount=RsArticle.getRow();//去除最後一行的行號
pageCount=((recCount%pageSize)==0?(recCount/pageSize):(recCount/pageSize)+1);//得到一共可以分多少頁
if(toPage!=null)
showPage=Integer.parseInt(toPage);
RsArticle.absolute((showPage-1)*pageSize+1);//跳到第showpage頁的第一條
for(int i=1;i<=pageSize;i++){
int NID=RsArticle.getInt("ID");
String img = RsArticle.getString("img");
String ttt = RsArticle.getString("times");
//ttt=ttt.substring(0,10);
%>
<tr class="STYLE1">
<td width="32" height="22" align="center" bgcolor="#BBDAFF"><%=NID%></td>

<td align="center" bgcolor="#BBDAFF" ><%=RsArticle.getString("bigname")%></td>

<td align="center" bgcolor="#BBDAFF" ><%=RsArticle.getString("smallname")%></td>

<td align="left" bgcolor="#BBDAFF" ><%=RsArticle.getString("Title")%></td>

<td align="center" bgcolor="#BBDAFF" ><a href="/<%=img%>" target="_blank"><%=img%></a></td>

<td align="center" bgcolor="#BBDAFF" ><%=ttt%></td>

<td width="64" align="center" bgcolor="#BBDAFF" class="STYLE1"><a href="Hanye_edit.jsp?id=<%=NID%>&modi=新聞">修改</a>|<a href="Hanye_Manages.jsp?id=<%=NID%>&op=del&BigClassName=<%=bgname%>" onclick="return confirm('刪除後將不能恢復,你確定刪除麼?')">刪除</a>&
copyright © 萬盛學電腦網 all rights reserved