Jsp Code For Refresh Page Automatically - Jsp

How to create auto page refresh using jsp?

Snippet Code


  
Rate this page :
  [ 0 votes]

Auto refreshing method in jsp allows you to refresh the webpage automatically by setting an time interval. Here, the auto refreshing is done through setIntHeader() method.

<%@ page import="java.io.*,java.util.*" %> <html> <head> <title>JSP code for refresh page automatically</title> </head> <body> <center> <h4>Auto Refresh Header--Page will refresh automatically after 5 seconds.</h4> <% // Set refresh, autoload time as 5 seconds response.setIntHeader("Refresh", 5); // Get current time 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: " + CT + "n"); %> </center> </body> </html>

Tags


Ask Questions

Ask Question