日期:2014-05-17  浏览次数:20772 次

为什么我用jsp做的网页聊天软件,另一个用户看不到一个用户发的信息
而且发信息的人员也不对,即明明是A发的,但是显示还是显示B发的,而且只能在A的界面可以看到,B的界面显示不出来
A发的信息
String audience = null;//说话的对象
String addresser = null;//发起者
String msg = null;//消息内容
String isPrivate;//是否 私聊
boolean isAutoRefresh = false;
audience = request.getParameter("towho");//说话的对象是从towho表单里面得到的
if (audience == null || audience.length() == 0) {
audience = "大家";
}
addresser = (String) session.getAttribute("Name");
msg = request.getParameter("msghide");
if (msg == null || msg.length() == 0) {
isAutoRefresh = true;
}
isPrivate = request.getParameter("private");
if (isPrivate == null) {
isPrivate = "off";
}
Vector Vmsg = null;//消息组 
Vector Vaddresser = null;
Vector VisPrivate = null;
Vector Vaudience = null;
synchronized (application) {
Vmsg = (Vector) application.getAttribute("msg");//从msg中取值
if (Vmsg == null) {
Vmsg = new Vector(30, 10);
}
Vaddresser = (Vector) application.getAttribute("addresser");
if (Vaddresser == null) {
Vaddresser = new Vector(30, 10);
}
VisPrivate = (Vector) application.getAttribute("isPrivate");
if (VisPrivate == null) {
VisPrivate = new Vector(30, 10);
}
Vaudience = (Vector) application.getAttribute("audience");
if (Vaudience == null) {
Vaudience = new Vector(30, 10);
}
if (!isAutoRefresh) {//消息不为空的时候
Vmsg.addElement(msg);//将msg加入到Vmsg中
Vaddresser.addElement(addresser);
Vaudience.addElement(audience);
VisPrivate.addElement(isPrivate);
synchronized (application) {
application.setAttribute("message", msg);
application.setAttribute("addresser", Vaddresser);
application.setAttribute("isPrivate", VisPrivate);
application.setAttribute("audience", Vaudience);
}
}
synchronized (application) {
int i, size = Vmsg.size();
String showmsg = null, tmpstr1, tmpstr2;
for (i = 0; i < size; i++) {
tmpstr1 = (String) VisPrivate.get(i);
if (tmpstr1.equals("off")) {//私聊的情况
showmsg = "[" + (String) Vaddresser.get(i) + "]对["
+ (String) Vaudience.get(i) + "]说:"
+ (String) Vmsg.get(i) + "<br>";
out.println(showmsg);
} else {
tmpstr1 = (String) Vaudience.get(i);
tmpstr2 = (String) Vaddresser.get(i);
if ((tmpstr1.equals(audience))
&& (tmpstr2.equals(addresser))) {
showmsg = "[" + (String) Vaddresser.get(i)
+ "]对[" + (String) Vaudience.get(i)
+ "]说:[私聊 ]" + (String) Vmsg.get(i)
+ "<br>";
out.println(showmsg);
}
}
}
这是一部分代码

------解决方案--------------------
你这是server端还是Client端?
用Timer了吗?