版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38262266/article/details/86618405
package message;
public class Message {
public Message(){}
private String name;
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
login.jsp
<%@ page contentType="text/html; charset=GB2312" pageEncoding= "GB2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>用户登录</title>
</head>
<element>
<body>
<center>
<form name="form" action="message.jsp">
<tr>
<td>
<h1>用户昵称:</h1>
</td>
<td>
<table>
<input name="mess" type="text"></table>
</td>
</tr>
<tr>
<table>
<input name="sub" type="submit"
value="提交">
</table>
</tr>
</form>
</center>
</body>
</element>
</html>
message.jsp
<%@ page contentType="text/html; charset=GB2312" pageEncoding= "GB2312"%>
<%@ page import="message.Message" %>
<%@ page import = "java.net.URLEncoder" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>留言板</title>
</head>
<element>
<body>
<%!
int k=1;
int i=0;
int j=0;
Message[] m=new Message[100];
int kkk=-1;
String[]s = new String[1000];
int kk=0;
%>
<%
request.setCharacterEncoding("GB2312");
String name = request.getParameter("name");
session.setAttribute("name",name);
String content = request.getParameter("content");
session.setAttribute("content",content);
String hhh = "The name is : "+name+"; "+"The content is : "+content;
if(name==null){
k=1;
}
else
{
k=2;
kk++;
kkk++;
}
%>
<%
if(k==1) {
request.setCharacterEncoding("GB2312");
String mess = request.getParameter("mess");
session.setAttribute("mess",mess);
//s[i]存储姓名
s[i] =mess;
i++;
//姓名为空时,返回本页面
if(mess==null||mess=="") {
k=1;
kk=1;
response.sendRedirect("login.jsp");
}
else
{
//s[i]存储姓名
for(j=0;j<i-1;j++) {
if(mess.equals(s[j])) {
out.println("用户名重复!");
break;
}
}
if(j==i-1) {
%>
<center>
<h2>留言板</h2>
<form name="form" method="post"
action="addmessage.jsp">
<input name="submit" type="submit" value="添加留言">
</table>
</form>
</center>
<%
}
}
}
else
{
m[kkk] = new Message();
m[kkk].setContent(content);
m[kkk].setName(name);
%>
<center>
<h2>留言板</h2>
</center>
<form name="form" method="post" action="addmessage.jsp">
<%for(int hh=0;hh<=kkk;hh++){%>
<center>
<table width="600" height="300" border="1" align="middle">
<tr>
<td align="center" valign="middle">
<a
href="showmessage.jsp?name=<% out.print(hhh);%>">
<%
out.print(m[hh].getName());
%>
</a>
</td>
<td align="center" valign="middle">
<%
out.print(m[hh].getContent());
%>
</td>
</tr>
</table>
<%if(hh==kkk){%>
<input name="submit" type="submit" value="添加留言">
<%}%>
</center>
<%}
}%>
</form>
</body>
</element>
</html>
addmessage.jsp
<%@ page contentType="text/html; charset=GB2312" pageEncoding= "GB2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>添加用户留言</title>
</head>
<element>
<body>
<center>
<form name="form1" method="post" action="message.jsp">
<h1>留言添加</h1>
<td align="center" valign="middle">
<h3>
输入姓名:
<input name="name" type="text"></h3>
</td>
<td align="center" valign="middle">
<h3>
输入留言:
<input name="content" type="text"></h3>
</td>
<td>
<input type="submit" value="提交"></td>
</form>
</center>
</body>
</element>
</html>
showmessage.jsp
<%@ page contentType="text/html; charset=GB2312" pageEncoding= "GB2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>添加用户留言</title>
</head>
<element>
<body style="background-color:lightblue">
<center>
<h1>留言显示</h1>
<h1>
<%
request.setCharacterEncoding("GB2312");
String name=request.getParameter("name");
name=new String(name.getBytes("iso-8859-1"),"gb2312");
String []a = name.split(";");
%>
<br />
<br>
<%
int i=0; for(i=0;i<a.length;i++) {
out.print(a[i]);
%>
</br>
<%}%>
<br>
<a href="message.jsp">返回登录界面</a>
</br>
</h1>
</center>
</body>
</element>
</html>