具体实现方法如下:
复制代码 代码如下:
<%@ 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 content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文章管理</title>
<link href="https://www.jb51.net/Style.css" type="text/css" />
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr>
<td background="images/admin_bg_1.gif"><strong><font color="#FFFFFF">--<span>内容管理</span></font></strong></td>
</tr>
<tr>
<td colspan="10">
</td>
</tr>
<tr>
<td background="images/admin_bg_1.gif">|
<%
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<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 href='Hanye_Manages.jsp?modi=新闻&BigClassName=<%=RsA.getString("smallname")%>'><%=RsA.getString("smallname")%></a> |
<%
}
RsA.close(); //关闭记录集对象
stmtA.close(); //关闭语句对象
%>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td valign="top" bgcolor="#ECF5FF">
<form action="list.asp?action=delall&modi=新闻" method="post">
<table cellpadding="3" cellspacing="2" bgcolor="#FFFFFF">
<tr>
<td background="images/admin_bg_1.gif" bgcolor="#BBDAFF" >ID</td>
<td background="images/admin_bg_1.gif" bgcolor="#BBDAFF" >新闻大类</td>
<td background="images/admin_bg_1.gif" bgcolor="#BBDAFF" >新闻小类</td>
<td background="images/admin_bg_1.gif" bgcolor="#BBDAFF" >新闻标题</td>
<td background="images/admin_bg_1.gif" bgcolor="#BBDAFF" >新闻图片</td>
<td background="images/admin_bg_1.gif" bgcolor="#BBDAFF" >发布时间</td>
<td background="images/admin_bg_1.gif" bgcolor="#BBDAFF">操作</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>
<td bgcolor="#BBDAFF"><%=NID%></td>
<td bgcolor="#BBDAFF" ><%=RsArticle.getString("bigname")%></td>
<td bgcolor="#BBDAFF" ><%=RsArticle.getString("smallname")%></td>
<td bgcolor="#BBDAFF" ><%=RsArticle.getString("Title")%></td>
<td bgcolor="#BBDAFF" ><a href="https://www.jb51.net/<%=img%>" target="_blank"><%=img%></a></td>
<td bgcolor="#BBDAFF" ><%=ttt%></td>
<td bgcolor="#BBDAFF"><a href="Hanye_edit.jsp?id=<%=NID%>&modi=新闻">修改</a>|<a href="Hanye_Manages.jsp?id=<%=NID%>&op=del&BigClassName=<%=bgname%>">删除</a></td>
</tr>
<%
if(!RsArticle.next())
break;
}
}
%>
<input type='hidden' value=>
</table>
<table cellpadding="0" cellspacing="0">
<tr>
<td background="images/admin_bg_1.gif">
<span><strong></strong>
</span>
<label>
</label>
</td>
<td background="images/admin_bg_1.gif">
<div>
共<%=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 method="post" action="Hanye_Manage.jsp"> <table cellspacing="0" cellpadding="0">
<tr>
<td><span>查询:</span>
<label>
<select>
<option value="ID">按ID查询</option>
<option value="title">按标题查询</option>
<option value="times">按时间查询</option>
</select>
</label>
<label>
<input type="text">
<input type="submit" value="提交">
</label> </td>
</tr>
</table>
</form>
<br></td>
</tr>
</table>
<%
RsArticle.close();
stmt_Article.close();
conn.close();
%>
</body>
</html>