import java.io.IOException; import java.util.Random; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @ClassName: ResponseDemo5 * @Description: 设置页面自动刷新 * @author amosli * @date 2013-10-16 下午11:57:08 */ public class ResponseDemo5 extends HttpServlet { private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("refresh", "2");//2是2秒的意思 String dataString = new Random().nextInt(10) + "";//输出0-9的随机数 response.getOutputStream().write(dataString.getBytes()); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }