日期:2014-05-16 浏览次数:20350 次
+================================================================================================+
JSP+JavaBean的留言板技术
下面附上源代码以方便学习:
Messages.html <HTML><HEAD> <TITLE> message board </TITLE></HEAD> <BODY> <center>留言板</center> <FORM action="addMessage.jsp" > <TABLE border=1 align="center"> <TR><TD>姓名:</TD><TD><input type="text" name="name" size=25> </TD></TR> <TR><TD>E-mail:</TD> <TD><input type="text" name="email" size=25></TD></TR> <TR><TD>主题:</TD> <TD><input type="text" name="title" size=25></TD></TR> <TR><TD>留言:</TD> <TD><textarea name="content" rows=7 cols=25></textarea> </TD></TR> <TR><TD colspan=3> <TABLE align="center" width="100%" cellspacing="0" cellpadding="0" > <TR> <TD align="center"><input type="submit" value="提交留言"></TD> <TD align="center"> <a href="viewMessages.jsp"><font size=2>查看留言</font></a></TD> <TD align="center"><input type="reset" value="重新填写"></TD> </TR></TABLE></TD> </TR></TABLE></FORM></BODY></HTML>
MessageData.java
package message;
public class MessageData
{ private String name,email,title,content;
//setter或者getter方法
public void setName(String name){this.name=name;}
public void setEmail(String email){ this.email=email;}
public void setTitle(String title){ this.title=title;}
public void setContent(String content){this.content=content;}
public String getName(){ return this.name;}
public String getContent(){ return this.content;}
public String getTitle(){ return this.title;}
public String getEmail(){ return this.email;}}
viewMessages.jsp
<%@ page contentType="text/html; charset=GBK" import="message.MessageData" %>
<%@ page import="java.util.*"%>
<jsp:useBean id="myBean" class="message.MessageBean" scope="page"/>
<HTML><HEAD><TITLE> show the message in the table </TITLE></HEAD>
<BODY><p align="center">所有留言</p>
<TABLE align="center" width="80%" border=1 >
<%
int message_count=0;
Collection <MessageData> messages=myBean.getAllMessa