Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jsp

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?

like image 282
Abhijit Bashetti Avatar asked Apr 20 '15 06:04

Abhijit Bashetti


4 Answers

You can try to add this:

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

So this will refresh the page every 10 seconds

like image 142
Rahul Tripathi Avatar answered Nov 13 '22 00:11

Rahul Tripathi


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.

like image 26
Abhishek Avatar answered Nov 13 '22 01:11

Abhishek


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.

like image 26
Mateusz Sroka Avatar answered Nov 13 '22 01:11

Mateusz Sroka


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.

like image 28
Saif Avatar answered Nov 13 '22 01:11

Saif