这个留言板可以添加留言薄,重新填写留言,查看所有留言。写了三个.jsp文件,
其代码如下
这是第一个代码也是整体的框架:
<%@
page contentType="text/html;charset=UTF-8"
%>
<%
String temp = new String();
temp = (String) application.getAttribute("num");
if (temp == null) {
application.setAttribute("num", "0");
}
%>
<html>
<head>
<title>留言板</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL, winName, features) {
window.open(theURL, winName, features);
}
-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<p align="center">
<b><font size="5" color="#FF6633">留言板</font></b>
</p>
<hr size="1">
<form name="form1" method="post" action="202-2.jsp">
<table width="60%" border="0" cellspacing="1" cellpadding="3"
align="center" bgcolor="#999999">
<tr bgcolor="#FFFFFF">
<td width="20%">留言作者:</td>
<td width="80%"><input type="text" name="txtaut"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%">留言标题:</td>
<td width="80%"><input type="text" name="txttit"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%">留言内容:</td>
<td width="80%"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%"> </td>
<td width="80%"><textarea name="txtart" cols="45" rows="7"></textarea>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%"> </td>
<td width="80%"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2">
<div align="center">
<input type="submit" name="cmdok" value="添加到留言薄">
<input
type="reset" name="cmdreset" value="重新填写留言">
<input
type="button" name="cmdread" value="查看所有留言"
onClick="MM_openBrWindow('203.jsp'),'','toolbar=no, location=no,status=no,menubar=no,scrollbars=no,width=400,height=400'">
</div>
</td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
下面是第二个代码,它是保存留言之后显示留言成功,然后可以成功的返回到主界面,代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>留言板</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<p align="center">
<b><font size="5" color="#FF6633">留 言 板 </font></b>
</p>
<hr size="1">
<%
int n;
String temp = new String();
String temp1 = new String();
String temp2 = new String();
String temp3 = new String();
temp1 = request.getParameter("txttit");
temp2 = request.getParameter("txtaut");
temp3 = request.getParameter("txtart");
n = temp1.length() * temp2.length() * temp3.length();
if (n != 0) {
temp = (String)application.getAttribute("num");
n = Integer.parseInt(temp);
n = n + 1;
temp = temp.valueOf(n);
application.setAttribute("num", temp);
application.setAttribute("tit" + temp, temp1);
application.setAttribute("aut" + temp, temp2);
application.setAttribute("art" + temp, temp3);
%>
<p> </p>
<p align="center">留言成功!</p>
<%}
else {
%>
<p align="center"><font color="#FF0000">不添加作者、标题和内容,留言失败!</font></p>
<%
}
%>
<p align="center">
<a href="201.jsp">返回首页</a>
</p>
</body>
</html>
最后一个代码是查看留言时候用到的:
<%@
page contentType="text/html;charset=UTF-8"
%>
<html>
<head>
<title>留言板</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<p align="center">
<b><font size="5" color="#FF6633">留 言 板 </font></b>
</p>
<hr size="1">
<%
int n;
String temp = new String();
String temp1 = new String();
String temp2 = new String();
String temp3 = new String();
temp = (String) application.getAttribute("num");
n = Integer.parseInt(temp);
if (n == 0) {
%>
<p> </p>
<p align="center">目前还没有文章!</p>
<%
} else {
%>
<table width="60%" border="1" cellspacing="0" cellpadding="5"
align="center" bordercolor="#999999">
<%
int i;
for (i = 1; i <= n; i++) {
temp = temp.valueOf(i);
temp1 = (String) application.getAttribute("tit" + temp);
temp2 = (String) application.getAttribute("aut" + temp);
temp3 = (String) application.getAttribute("art" + temp);
%>
<tr>
<td bgcolor="#CCFFCC" height="27"><b><%=temp%>.标题:<%=temp1%>作者:
<%=temp2%></b></td>
</tr>
<tr>
<td><%=temp3%></td>
</tr>
<%
}
}
%>
</table>
<p align="center"> </p>
</body>
</html>
你可以改变里面的内容达到自己想要的结果