index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>留言板</title>
</head>
<body>
<form action="process.jsp" method=post>
请输入您的姓名:<input type="text" name="name"><br><br>
请输入标题:<input type="text" name="title"><br><br>
请输入留言内容:<br>
    
<textarea rows="10" cols="30" name="content"></textarea><br><br>
<input type="submit" value="submit">
</form>
<br>
<form action="show.jsp">
<input type="submit" value="查看留言板">
</form>
</body>
</html>
process.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*,java.text.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("name");
String title=request.getParameter("title");
String content=request.getParameter("content");
if(name=="")
{
name="游客"+(int)(Math.random()*1000);
}
if(title=="")
{
title="无标题";
}
if(content==""){
content="无内容";
}
Date time=new Date();
DateFormat bf = new SimpleDateFormat("MM.dd HH:mm");
String format = bf.format(time);
out.println(format);
String s=name+"#"+title+"#"+format+"#"+content+"#";
addMessage(s);
%>
<%!
Vector v=new Vector();
ServletContext application;
synchronized void addMessage(String s){
application=getServletContext();
v.add(s);
application.setAttribute("Message", v);
}
%>
<a href="index.jsp"> 返回首页</a>
</body>
</html>
show.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Vector v=(Vector)application.getAttribute("Message");
%>
<h1>这是一个留言板</h1>
<%
for(int i=0;i<v.size();i++)
{
String a=(String)v.elementAt(i);
String[] a1=a.split("#");
%>
姓名:<%=a1[0] %><br>
主题:<%=a1[1] %><br>
留言时间:<%=a1[2] %><br>
留言内容:<%=a1[3] %><br>
<hr>
<%
}
%>
</table>
</body>
</html>
实现图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9e7841728764a632bca61e7813e4f332.png)