java comet tomcat推送
当有访问时 public void event(CometEvent event) throws IOException, ServletException 这个方法为什么没执行public void event(CometEvent event) throws IOException, ServletException {
HttpServletRequest request = event.getHttpServletRequest();
HttpServletResponse response = event.getHttpServletResponse();
// 昵称
String name = "wo";
System.out.println("+++++++++++23");
System.out.println(response);
if (event.getEventType() == CometEvent.EventType.BEGIN) {
// Http连接空闲超时
event.setTimeout(Integer.MAX_VALUE);
log("Begin for session: " + request.getSession(true).getId());
// 创建Comet Iframe
PrintWriter writer = response.getWriter();
writer
.println("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">");
writer
.println("<html><head><script type=\"text/javascript\">var comet = window.parent.comet;</script></head><body>");
writer.println("<script type=\"text/javascript\">");
writer.println("var comet = window.parent.comet;");
writer.println("</script>");
writer.flush();
// for chrome
if (request.getHeader("User-Agent").contains("KHTML")) {
for (int i = 0; i < 100; i++) {
writer.print("<input type=hidden name=none value=none>");
}
writer.flush();
}
writer.flush();
synchronized (connections) {
connections.put(name, response);
}
} else if (event.getEventType() == CometEvent.EventType.ERROR) {
log("Error for session: " + request.getSession(true).getId());
synchronized (connections) {
connections.remove(name);
}
event.close();
} else if (event.getEventType() == CometEvent.EventType.END) {
} else if (event.getEventType() == CometEvent.EventType.READ) {
InputStream is = request.getInputStream();
byte[] buf = new byte[512];
do {
int n = is.read(buf); // can throw an IOException
if (n > 0) {
log("Read " + n + " bytes: " + new String(buf, 0, n)
+ " for session: "
+ request.getSession(true).getId());
} else if (n < 0) {
return;
}
} while (is.available() > 0);
}
}
tomcat 配置都配好了。<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="8088" redirectport="8443" connectiontimeout="20000" />
web.xml也
<servlet-mapping>
<servlet-name>CServlet</servlet-name>
<url-pattern>/CServlet</url-pattern>
</servlet-mapping>
<!-- Grails dispatcher servlet -->
<servlet>
<servlet-name>grails</servlet-name>
<servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> --------------------编程问答-------------------- 是直接返回了么?还是卡住了?
补充:Java , Web 开发