创建一个登陆页面http://shop63873662.taobao.com
<%@ page language="java" pageEncoding="gb2312"%>
创建一个聊天页面名字为chart.jsp
<%@ page contentType="text/html; charset=GBK" import="java.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%response.setIntHeader("Refresh",10); %>
}
//获取用户发言
String word = request.getParameter("yourWords");
//从application中所有用户历史发言
String chart = (String)application.getAttribute("chart");
//当发言到一定长度就清空,以免耗尽内存
if(chart!=null&&chart.length()>10000) application.setAttribute("chart","");
if(name!=null&&word!=null){
//组装用户在屏幕上发言语句:
String userword=new Date()+" 用户名:["+name+"]说:"+word;
//将用户发言存入历史记录中
chart+=userword+"/r/n";
application.setAttribute("chart",chart);
}
%>
<% if(name!=null) out.print(name+"说");%>
<%}catch(Exception e){
e.printStackTrace();
}%>
这个一个简单实现聊天的代码如果有不足的可以自行扩展。。呵呵