使用response实现定时刷新

来源:互联网 发布:js dom是什么 编辑:程序博客网 时间:2024/04/30 00:16

定时刷新的原理:设置HTTP响应头Refresh:1;url=http://localhost:8080/demo/index.jsp

方法一、使用response.setHeader();方法

[java] view plain copy
  1. response.getWriter().write(new Date().toLocaleString());  
  2. response.setHeader("Refresh""1");  

方法二、使用HTML的<meta>元素

[html] view plain copy
  1. <meta http-equiv="refresh" content="3;url=/demo/index.jsp">    

实例:三秒后回到主页的实现方法

在Servlet中,重定向到ok.html,ok.html的内容如下

[html] view plain copy
  1. <html>  
  2.   <head>  
  3.         <meta http-equiv="refresh" content="3;url=/demo/index.jsp">     
  4.   </head>  
  5.   <body>  
  6.     恭喜,3秒后回到主页...  
  7.   </body>  
  8. </html>  
原创粉丝点击