protected void begin(CometEvent event, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log("Begin for session: " + request.getSession(true).getId()); response.setContentType("text/html; charset=" + CHARSET); PrintWriter writer = response.getWriter(); writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"); writer.println("<html><head><title>JSP Chat</title></head><body bgcolor=\"#FFFFFF\">"); writer.println("<div>Welcome to the chat. <a href='chat'>Click here to reload this window</a></div>"); writer.flush(); synchronized(connections) { connections.add(response); } messageSender.send("Tomcat", request.getSession(true).getAttribute("nickname") + " joined the chat."); }
protected void end(CometEvent event, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log("End for session: " + request.getSession(true).getId()); synchronized(connections) { connections.remove(response); } PrintWriter writer = response.getWriter(); writer.println("</body></html>"); event.close(); }
protected void read(CometEvent event, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { InputStream is = request.getInputStream(); byte[] buf = new byte[512]; while (is.available() > 0) { log("Available: " + is.available()); int n = is.read(buf); if (n > 0) { log("Read " + n + " bytes: " + new String(buf, 0, n) + " for session: " + request.getSession(true).getId()); } else if (n < 0) { log("End of file: " + n); end(event, request, response); return; } } }
protected void error(CometEvent event, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log("Error for session: " + request.getSession(true).getId()); synchronized(connections) { connections.remove(response); } event.close(); }
protected void begin(CometEvent event, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log("Begin for session: " + request.getSession(true).getId()); PrintWriter writer = response.getWriter(); writer.println("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">"); writer.println("<html><head><title>JSP Chat</title></head><body bgcolor=\"#FFFFFF\">"); writer.flush(); synchronized(connections) { connections.add(response); } }
public void error(CometEvent event,HttpServletRequest request, HttpServletResponse response ){ }