jsp利用application实现留言板功能
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
</FO百度文库M>
</BODY></HTML>
Message.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.util.*" %>
<HTML><BODY>
<%!Vector v=new Vector();
out.print("<table border=2>");
out.print("<tr>");
out.print("<td bagcolor=yellow>"+"姓名"+"</td>");
out.print("<td bagcolor=yellow>"+"主题"+"</td>");
out.print("<td bagcolor=yellow>"+"留言时间"+"</td>");
out.print("<td bagcolor=yellow>"+"留言内容"+"</td>");
out.print("</tr>");
for(int i=0;i<v.size();i++){
out.print("<tr>");
String message=(String)v.elementAt(i);
利用application实现留言板功能。
Submit.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<HTML><BODY>
<FORM action="message.jsp" method="post" name="form">
<p>姓名:
out.print("</table>");
%>
</BODY></HTML>
<BR><Input type="submit" value="提交" name="submit">
</FORM>
<FORM action="showmessage.jsp" method="post" name="form1">
<Input type="submit" value="查看留言板" name="look">
if(k<number-1){
out.print("<td bgcolor=yellow>"+str+"</td>");
}
else{
out.print("<td><TextArea rows=3 cols=12>"+str+"</TextArea></td>");
}
}
}
out.print("</tr>");
StringTokenizer fenxi=new StringTokenizer(message,"#");
out.print("<tr>");
int number=fenxi.countTokens();
for(int k=0;k<number;k++){
String str=fenxi.nextToken();
<Input type="text" name="name">
<BR>主题:
<Input type="text" name="zhuti">
<BR>留言内容:
<BR><TextArea name="messages" ROWS="10" COLS="20" WRAP="physical" >
</TextArea>
ServletContext application;
synchronized void sendMessage(String s){
application=getServletContext();
v.add(s);
application.setAttribute("Mess",v);
}
%>
<% request.setCharacterEncoding("GBK");
String name=request.getParameter("name");
String zhuti=request.getParameter("zhuti");
String messages=request.getParameter("messages");
if(name==null){
name="guest"+(int)(Math.random()*10000);
}
if(zhuti==null){
zhuti="无标题";
}
if(messages==null){
messages="无信息";
}
String time=new Date().toString();
String s="#"+name+"#"+zhuti+"#"+time+"#"+messages+"#";
sendMessage(s);
%>
</BODY></HTML>
Showmessage.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.util.*" %>
<HTML><BODY>
<% Vector v=(Vector)application.getAttribute("Mess");
</BODY></HTML>
Message.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.util.*" %>
<HTML><BODY>
<%!Vector v=new Vector();
out.print("<table border=2>");
out.print("<tr>");
out.print("<td bagcolor=yellow>"+"姓名"+"</td>");
out.print("<td bagcolor=yellow>"+"主题"+"</td>");
out.print("<td bagcolor=yellow>"+"留言时间"+"</td>");
out.print("<td bagcolor=yellow>"+"留言内容"+"</td>");
out.print("</tr>");
for(int i=0;i<v.size();i++){
out.print("<tr>");
String message=(String)v.elementAt(i);
利用application实现留言板功能。
Submit.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<HTML><BODY>
<FORM action="message.jsp" method="post" name="form">
<p>姓名:
out.print("</table>");
%>
</BODY></HTML>
<BR><Input type="submit" value="提交" name="submit">
</FORM>
<FORM action="showmessage.jsp" method="post" name="form1">
<Input type="submit" value="查看留言板" name="look">
if(k<number-1){
out.print("<td bgcolor=yellow>"+str+"</td>");
}
else{
out.print("<td><TextArea rows=3 cols=12>"+str+"</TextArea></td>");
}
}
}
out.print("</tr>");
StringTokenizer fenxi=new StringTokenizer(message,"#");
out.print("<tr>");
int number=fenxi.countTokens();
for(int k=0;k<number;k++){
String str=fenxi.nextToken();
<Input type="text" name="name">
<BR>主题:
<Input type="text" name="zhuti">
<BR>留言内容:
<BR><TextArea name="messages" ROWS="10" COLS="20" WRAP="physical" >
</TextArea>
ServletContext application;
synchronized void sendMessage(String s){
application=getServletContext();
v.add(s);
application.setAttribute("Mess",v);
}
%>
<% request.setCharacterEncoding("GBK");
String name=request.getParameter("name");
String zhuti=request.getParameter("zhuti");
String messages=request.getParameter("messages");
if(name==null){
name="guest"+(int)(Math.random()*10000);
}
if(zhuti==null){
zhuti="无标题";
}
if(messages==null){
messages="无信息";
}
String time=new Date().toString();
String s="#"+name+"#"+zhuti+"#"+time+"#"+messages+"#";
sendMessage(s);
%>
</BODY></HTML>
Showmessage.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.util.*" %>
<HTML><BODY>
<% Vector v=(Vector)application.getAttribute("Mess");