Abhijit Bashetti
Abhijit Bashetti

Reputation: 8658

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

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

How can achieve it?

Upvotes: 7

Views: 22023

Answers (4)

Saif
Saif

Reputation: 7042

In jsp add

<%
  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 Tripathi solution is the best as html tag will work perfectly in jsp.

Upvotes: 1

Abhishek
Abhishek

Reputation: 878

You can use 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.

Upvotes: 6

Mateusz Sroka
Mateusz Sroka

Reputation: 2335

Or you can use javascript to do this:

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

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

Upvotes: 1

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

You can try to add this:

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

So this will refresh the page every 10 seconds

Upvotes: 7

Related Questions