jsp+mysql制作简单的留言板(6)
发表于:2007-07-04来源:作者:点击数:
标签:
其结构与board.jsp差不多的,只不过在每一笔留言增加了一个单选复选框便于删除: html title专家留言板/title body %@page import= java .sql.*% %@page contentType=text/html;charset=GB2312% %@include file=opendata.jsp% % int count=0,lastp,numf,numl
其结构与board.jsp差不多的,只不过在每一笔留言增加了一个单选复选框便于删除:
<html>
<title>专家留言板</title>
<body>
<%@page import="
java.sql.*"%>
<%@page contentType="text/html;charset=GB2312"%>
<%@include file="opendata.jsp"%>
<%
int count=0,lastp,numf,numl,prep,nextp,pageno;
if(request.getParameter("pageno")==null)
{
pageno=0;
}
else
pageno=Integer.parseInt(request.getParameter("pageno"));
sql="select * from message";
rs=smt.executeQuery(sql);
while(rs.next())
count++;
lastp=(int)Math.ceil((double)count/5);
if(pageno==0||pageno>lastp)
pageno=lastp;
numf=pageno*5-4;
numl=numf+4;
if(pageno==1)
prep=1;
else
prep=pageno-1;
if(pageno==lastp)
nextp=lastp;
else
nextp=pageno+1;
sql="select * from message where id between "+numf+" and "+numl;
rs=smt.executeQuery(sql);
%>
<font size=7 color=green>专家留言板 </font>
<font color=#008080>站长使用画面</font>
<hr>
<center>
<form action=board.jsp method=POST>
<table boder=0>
<tr>
<
td>目前的页次:<font size=2 color=red><%=pageno%></font>/<font color=blue><%=lastp%></font></td>
<td><a href=manager.jsp?pageno=<%=prep%>>[上一页]</a></td>
<td><a href=manager.jsp?pageno=<%=nextp%>>[下一页]</a></td>
<td><a href=manager.jsp?pageno=1>[第一页]</a></td>
<td><a href=manager.jsp>[最后一页]</a></td>
<td>输入页次<input type=text size=3 name=pageno></td>
<td><input type=submit name=SEND value=送出></td>
<td><a href=password.jsp><font color=red size="5">
<i>站长钻用</i></font></a></td>
</tr>
</table>
</form>
<form action=delete.jsp?pageno=<%=pageno%>method=POST>
<%
String name,email,subject,time,sex,memo;
int id;
while(rs.next())
{
name=rs.getString(1);
email=rs.getString(2);
subject=rs.getString(3);
time=rs.getString(4);
sex=rs.getString(5);
memo=rs.getString(6);
id=rs.getInt(7);
out.print("<p align=left><input type=checkbox name=D"+id+"value=del>删除第<font color=red>"+id+"</font>");
out.print("<center>");
out.print("<table border=1>");
out.print("<tr><td bgcolor=yellow>姓名</td><td>"+name+"</td></tr>");
out.print("<tr><td bgcolor=yellow>E-mail</td><td>"+email+"</td></tr>");
out.print("<tr><td bgcolor=yellow>时间</td><td>"+time+"</td></tr>");
out.print("<tr><td bgcolor=yellow>主题</td><td>"+subject+"</td></tr>");
out.print("<tr><td valign=top bgcolor=yellow>留言</td><td>"+memo+"<img src="+sex+"></td></tr>");
out.print("</table></p>");
}
%>
<input type=submit name=SEND value=确定删除>
<input type=reset value=重新选取>
</form>
<hr>
<center>
<a href=message.html>我要留言</a>
<a href=manager.jsp>查看留言</a>
</body>
</html>
而下面的是delete.jsp程序:
<%
String para,value;
int pageno,numf,numl;
if(request.getParameter("pageno")==null)
pageno=0;
else
pageno=Integer.parseInt(request.getParameter("pageno"));
numf=pageno*5-4;
numl=numf+4;
for(int i=numf;i<=numl;i++)
{
para="D"+String.valueOf(i);
value=request.getParameter(para);
if(value!=null)
{
sql="delete from message where id="+i;
smt.executeUpdate(sql);
}
}
sql="alter table message drop id";
smt.executeUpdate(sql);
sql="alter table message add id int auto_increment primary key";
smt.executeUpdate(sql);
response.sendRedirect("manager.jsp");
%>
好了所有的代码都完成了;你可以试一下:
原文转自:http://www.ltesting.net