package cn.base.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class KeepAliveServlet extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		res.setContentType("text/plain");
		ServletOutputStream out = res.getOutputStream();
		out.print("receive   user   message:");
		out.println(req.getParameter("message"));
	}

	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		int i = 0;
		ServletOutputStream out = res.getOutputStream();
		while (true) {
			try {
				i++;
				res.setContentType("text/plain");
				out.print("<script>parent.window.tranH('hello world i=" + i
						+ "!')</script>");
				out.flush();
				Thread.sleep(1000);
				System.out.println("redhigh test: keep alive");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public String getServletInfo() {
		return "returns   a   string   representation   of   the   current   time";
	}
}
