你的位置:首页 > Java教程

[Java教程]jsp留言板雏形


编写一个简单的留言簿,实现添加留言和显示留言内容的功能

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2   pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>登录页面</title> 8 </head> 9 <body>10 11 <form action="liuyan.jsp" method="post"> 12  <table width="300" height="300" border="0" align="center">13    <tr height="80" align="center">14      <td colspan="2"><font size="24">留言发布栏</font></td></tr>15    <tr height="30">16      <td width="80" align="right">用户名:</td>             17      <td><input type="text" name="name"></td></tr>18    <tr height="30">19      <td width="80" align="right"> 密&nbsp;&nbsp;码:</td>20      <td> <input type="password" name="password"></td></tr>21    <tr height="20"><td colspan="2"></td></tr>22    <tr height="30">23      <td width="80" align="right">标&nbsp;&nbsp;题:</td>24      <td><input type="text" name="biaoti"></td></tr>25    <tr><td width="80" align="right">内&nbsp;&nbsp;容:</td>26      <td><textarea name="neirong" rows="4" cols="20"></textarea></td></tr>27    <tr><td height="40" align="center" colspan="2">28     <input type="submit" value="提交"></td></tr>29  </table>30 </form>31 </body>32 </html>

 1 <%@page import="javax.swing.text.Style"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3   pageEncoding="UTF-8"%> 4   <%@ page import="java.util.*" %> 5   <%@ page import="java.text.SimpleDateFormat" %> 6 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 7 <html> 8 <head> 9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">10 <title>留言板</title>11 </head>12 <body>13 <%= "<font size='36'><b><i>留言板</i></b></font>" %>14 <%! String str= ""; %>15 <%16 String bt = new String( request.getParameter("biaoti").getBytes("ISO-8859-1"),"UTF-8");17 String nr = new String( request.getParameter("neirong").getBytes("ISO-8859-1"),"UTF-8");18 String xm = new String( request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");19 20 Date date = new Date();21 SimpleDateFormat da = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");22 String time = da.format(date);23 if(bt.isEmpty()){24   str += "<br>标&nbsp;&nbsp;题:标题被吃了" + "<br>内&nbsp;&nbsp;容:" + nr + "<br>发布者:" + xm + "<br>发布时间:" + time + "<hr>";25 }else{26   str += "<br>标&nbsp;&nbsp;题:" + bt + "<br>内&nbsp;&nbsp;容:" + nr + "<br>发布者:" + xm + "<br>发布时间:" + time + "<hr>";27 }28 %>29 30 <%= str %>31 32 </body>33 </html>

 

运行: