jsp分页显示完整实例
网络编程 2021-07-05 11:23www.168986.cn编程入门
这篇文章主要介绍了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://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://.w3./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="" 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></td>
</tr>
<%
if(!RsArticle.next())
break;
}
}
%>
<input name='AllID' type='hidden' value=>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="STYLE1">
<td width="50%" align="left" background="images/admin_bg_1.gif">
<span class="t2"><strong></strong>
</span>
<label>
</label>
</td>
<td width="56%" align="center" background="images/admin_bg_1.gif">
<div align="left" class="t2">
共<%=pageCount%>页 <% for(int i=1;i<=pageCount;i++){ %> <% if(i==showPage){ %><b><%=i %></b><% }else{ %>[<a href='Hanye_Manages.jsp?BigClassName=<%=bgname%>&page=<%=i %>&modi=新闻'><%=i %></a>] <% } } %>
</div></td>
</tr>
</table>
</form>
<form name="form1" method="post" action="Hanye_Manage.jsp"> <table width="51%" border="0" cellspacing="0" cellpadding="0">
<tr class="t4">
<td width="34%" height="23"><span class="STYLE1">查询</span>
<label>
<select name="select">
<option value="ID">按ID查询</option>
<option value="title">按标题查询</option>
<option value="times">按时间查询</option>
</select>
</label>
<label>
<input type="text" name="k">
<input name="Submit" type="submit" class="t5" value="提交">
</label> </td>
</tr>
</table>
</form>
<br></td>
</tr>
</table>
<%@include file ="../inc/ChkPwd.jsp"%>
<%@include file="../DB.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://.w3./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="" 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></td>
</tr>
<%
if(!RsArticle.next())
break;
}
}
%>
<input name='AllID' type='hidden' value=>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="STYLE1">
<td width="50%" align="left" background="images/admin_bg_1.gif">
<span class="t2"><strong></strong>
</span>
<label>
</label>
</td>
<td width="56%" align="center" background="images/admin_bg_1.gif">
<div align="left" class="t2">
共<%=pageCount%>页 <% for(int i=1;i<=pageCount;i++){ %> <% if(i==showPage){ %><b><%=i %></b><% }else{ %>[<a href='Hanye_Manages.jsp?BigClassName=<%=bgname%>&page=<%=i %>&modi=新闻'><%=i %></a>] <% } } %>
</div></td>
</tr>
</table>
</form>
<form name="form1" method="post" action="Hanye_Manage.jsp"> <table width="51%" border="0" cellspacing="0" cellpadding="0">
<tr class="t4">
<td width="34%" height="23"><span class="STYLE1">查询</span>
<label>
<select name="select">
<option value="ID">按ID查询</option>
<option value="title">按标题查询</option>
<option value="times">按时间查询</option>
</select>
</label>
<label>
<input type="text" name="k">
<input name="Submit" type="submit" class="t5" value="提交">
</label> </td>
</tr>
</table>
</form>
<br></td>
</tr>
</table>
<%
RsArticle.close();
stmt_Article.close();
conn.close();
%>
</body>
</html>
希望本文所述对大家的jsp程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程