import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class KeepAlive extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); // Set up a PrintStream built around a special output stream ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024); PrintWriter out = new PrintWriter(bytes, true); // true forces flushing out.println(""); out.println("Hello World"); out.println(""); out.println("Hello World"); out.println(""); // Set the content length to the size of the buffer res.setContentLength(bytes.size()); // Send the buffer bytes.writeTo(res.getOutputStream()); } }