JSP每隔指定的时间段自动刷新页面

<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
<title>Auto Refresh Header Example</title>
</head>
<body>
<center>
<h2>Auto Refresh Header Example</h2>
<%    response.setIntHeader("Refresh", 5);    
      Calendar calendar = new GregorianCalendar();    
      String am_pm;    
      int hour = calendar.get(Calendar.HOUR);    
      int minute = calendar.get(Calendar.MINUTE);    
      int second = calendar.get(Calendar.SECOND);    
      if(calendar.get(Calendar.AM_PM) == 0)       
         am_pm = "AM";    
      else       
         am_pm = "PM";    
      String CT = hour+":"+ minute +":"+ second +" "+ am_pm;    
      out.println("Current Time is: " + CT + "\n"); 
%>
</center>
</body>
</html>

服务器端渲染,所以Chrome开发者工具network标签页里看不到response:

JSP每隔指定的时间段自动刷新页面

可以看到每隔5秒钟的时间间隔效果:

JSP每隔指定的时间段自动刷新页面

上一篇:Docker解析及轻量级PaaS平台演练(四)--Fig相关介绍


下一篇:iphone手机微信端html5 Geolocation定位失效的问题