编写一个简单的留言簿,实现添加留言和显示留言内容的功能
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>登录页面</title>
</head>
<body> <form action="liuyan.jsp" method="post">
<table width="300" height="300" border="0" align="center">
<tr height="80" align="center">
<td colspan="2"><font size="24">留言发布栏</font></td></tr>
<tr height="30">
<td width="80" align="right">用户名:</td>
<td><input type="text" name="name"></td></tr>
<tr height="30">
<td width="80" align="right"> 密 码:</td>
<td> <input type="password" name="password"></td></tr>
<tr height="20"><td colspan="2"></td></tr>
<tr height="30">
<td width="80" align="right">标 题:</td>
<td><input type="text" name="biaoti"></td></tr>
<tr><td width="80" align="right">内 容:</td>
<td><textarea name="neirong" rows="4" cols="20"></textarea></td></tr>
<tr><td height="40" align="center" colspan="2">
<input type="submit" value="提交"></td></tr>
</table>
</form>
</body>
</html>
<%@page import="javax.swing.text.Style"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<!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=UTF-8">
<title>留言板</title>
</head>
<body> <%! String str= ""; %>
<%
String bt = new String( request.getParameter("biaoti").getBytes("ISO-8859-1"),"UTF-8");
String nr = new String( request.getParameter("neirong").getBytes("ISO-8859-1"),"UTF-8");
String xm = new String( request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8"); Date date = new Date();
SimpleDateFormat da = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = da.format(date);
if(bt.isEmpty()){
str += "<br>标 题:标题被吃了" + "<br>内 容:" + nr + "<br>发布者:" + xm + "<br>发布时间:" + time + "<hr>";
}else{
str += "<br>标 题:" + bt + "<br>内 容:" + nr + "<br>发布者:" + xm + "<br>发布时间:" + time + "<hr>";
}
%>
<table width="800" border="0" align="center">
<tr height="80" align="center"><td><%= "<font size='36'><b><i>留言板</i></b></font>" %></td></tr>
<tr><td><%= str %></td></tr> </table> </body>
</html>
运行: