java 如何在给定时间(或间隔)后刷新jsp页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29741026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:50:15  来源:igfitidea点击:

How to refresh the jsp page after a given time(or interval)?

javajsp

提问by Abhijit Bashetti

I would like to refresh/reload my jsp page after a certain time interval. Consider the time interval is of 5 minutes.

我想在一定时间间隔后刷新/重新加载我的 jsp 页面。考虑时间间隔为 5 分钟。

How can achieve it?

怎样才能实现呢?

采纳答案by Abhishek

You can use public void setIntHeader(String header, int headerValue)

您可以使用 public void setIntHeader(String header, int headerValue)

response.setIntHeader("Refresh",300)

This method sends back header "Refresh" to the browser along with an integer value which indicates time interval in seconds.

此方法将标头“Refresh”连同一个整数值一起发送回浏览器,该整数值指示以秒为单位的时间间隔。

回答by Rahul Tripathi

You can try to add this:

您可以尝试添加以下内容:

<META HTTP-EQUIV="Refresh" CONTENT="10">

So this will refresh the page every 10 seconds

所以这将每 10 秒刷新一次页面

回答by Mateusz Sroka

Or you can use javascript to do this:

或者您可以使用 javascript 来执行此操作:

<script type="text/javascript">
  setTimeout(function(){
    location = ''
  },60*1000)
</script>

setTimeoutwill reload the page after a specified number of milliseconds, hence 60 * 1000 = 1m.

setTimeout将在指定的毫秒数后重新加载页面,因此 60 * 1000 = 1m。

回答by Saif

In jsp add

在jsp中添加

<%
  response.setIntHeader("Refresh", time_in_second); //in your case 60*5=300 (for 5 min)
%>

If you want to do it without using java code then Rahul Tripathisolution is the best as html tag will work perfectly in jsp.

如果你想在不使用 java 代码的情况下做到这一点,那么Rahul Tripathi解决方案是最好的,因为 html 标签将在 jsp 中完美运行。