input.jsp
<%@ page contentType="text/html;Charset=GBK" %>
<html><body><center>
<form action="conduct.jsp" method=post>
<% String username = (String)session.getAttribute("name");
%>
用户:<%= username %>
<textarea name="message" cols=50 rows=4>
</textarea>
<input type="submit" name="submit" value="发送">
<br>
<%
session.setAttribute("name",username);
%>
<form>
</body></html>
conduct.jsp
<%@ page contentType="text/html;Charset=GBK" %>
<%@ page import="java.util.*" %>
<html><body><center>
<%!
Vector v = new Vector();
ServletContext application;
synchronized void sendMessage(String message){
application = getServletContext();
application.setAttribute("mess",v);
}
%>
<%String username = (String)session.getAttribute("name");
String message1 = request.getParameter("message");
String message = username+" : "+"<br>"+message1;
v.add(message);
sendMessage(message);
response.sendRedirect("input.jsp");
%>
<%--response.sendRedirect("chatHall.jsp");--%>
</body></html>
charHall.jsp
<%@ page contentType="text/html;Charset=GBK" %>
<%@ page import="java.util.*" %>
<html>
<meta http-equiv="refresh" content="1" url=chatHall.jsp">
<body>
<%String username = (String)session.getAttribute("name");
Vector v = (Vector)application.getAttribute("mess");
int i = v.size()-1;
while(i>0){
String message = (String)v.elementAt(i);
out.print(message+"<br>"+"<hr >"+"<br>");
i--;
}
%>
</body></html>
chatlist.jsp
<%@ page contentType="text/html;charset=GBK" %>
<html><body><center>
<form action="">
</form>
</body></html>
posted on 2009-09-24 11:11
鹏凌 阅读(188)
评论(0) 编辑 收藏 所属分类:
Java --j2ee