Servlet奇怪问题
以下是练习时写的聊天服务器.
比如我输入 "xxxxxx "按了提交,以下的Servlet收到后广播给所有客户端.
现在奇怪的是客户端收到的是两条一相同的信息.doGet()我用log()输出也看了有两次调用.看了好久找不出原因,麻烦那位帮我看看.小弟这里先谢了.
用了Observable和Observer的事件框架.
public class ChatServlet extends HttpServlet {
protected MessageSource source = new MessageSource();
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws
ServletException,
IOException {
this.log( "doGet start! ");
res.setContentType( "text/plain ");
PrintWriter out = res.getWriter();
out.println(this.getNextMessage());
out.flush();
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException {
String message = req.getParameter( "message ");
if (message != null)
this.broadcastMessage(message);
res.setStatus(res.SC_NO_CONTENT);
}
public String getNextMessage() {
return new MessageSink().getNextMessage(source);
}
public void broadcastMessage(String message) {
source.sendMessage(message);
}
}
public class ChatServlet extends HttpServlet {
protected MessageSource source = new MessageSource();
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException {
this.log( "doGet start! ");
res.setContentType( "text/plain ");
PrintWriter out = res.getWriter();
out.println(this.getNextMessage());
out.flush();
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException {
String message = req.getParameter( "message ");
if (message != null)
this.broadcastMessage(message);
res.setStatus(res.SC_NO_CONTENT);
}
public String getNextMessage() {
return new MessageSink().getNextMessage(source);
}
&nb