jsp分页显示完整实例
程序员文章站
2022-06-05 13:15:52
本文实例讲述了jsp分页显示的实现方法。分享给大家供大家参考。
具体实现方法如下:
复制代码 代码如下:<%@ page contenttype="text/ht...
本文实例讲述了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></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://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></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程序设计有所帮助。
上一篇: 华为手表一直重启怎么解决?
下一篇: 30个提高Web程序执行效率的好经验分享