您的位置:首页 > 其它

使用response实现定时刷新

2017-12-13 14:23 246 查看
定时刷新的原理:设置HTTP响应头Refresh:1;url=http://localhost:8080/demo/index.jsp

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

[java] view
plain copy

response.getWriter().write(new Date().toLocaleString());  

response.setHeader("Refresh", "1");  

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

[html] view
plain copy

<meta http-equiv="refresh" content="3;url=/demo/index.jsp">    

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

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

[html] view
plain copy

<html>  

  <head>  

        <meta http-equiv="refresh" content="3;url=/demo/index.jsp">     

  </head>  

  <body>  

    恭喜,3秒后回到主页...  

  </body>  

</html>  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: