Create an empty servlet class, like the following:
import javax.servlet.*;
public class HiddenCometServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private String contextPath = null;
@Override
public void init(ServletConfig config) throws ServletException {}
@Override
protected void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {}
@Override
protected void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {);
}
Import the following Comet packages into the servlet class:
import com.sun.grizzly.comet.CometContext; import com.sun.grizzly.comet.CometEngine; import com.sun.grizzly.comet.CometEvent; import com.sun.grizzly.comet.CometHandler;
Import these additional classes that you need for incrementing a counter and writing output to the clients:
import java.io.IOException; import java.io.PrintWriter; import java.util.concurrent.atomic.AtomicInteger;
Add a private variable for the counter:
private final AtomicInteger counter = new AtomicInteger();