public void setIntHeader(String header, int headerValue)
This strategy sends back header “Refresh” to the program alongside a number worth which shows time interim in seconds.
<%@ page import="java.io.*,java.text.*,java.util.*"%> <html> <head> <title>Auto Refresh Header Example</title> </head> <body bgcolor="skyblue"> <center> <img src=E:/splessons.png></br></br> Visit <a href="https://www.splessons.com">SPLessons.com</a> <h2>Auto Refresh Header Example</h2> <% // Page will be auto refresh after 1 seconds response.setIntHeader("Refresh", 1); // Get Current Time DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); out.println(dateFormat.format(cal.getTime())); %></center> </body> </html>
Here just imported the packages such as java.io.*, java.text.*, java.util.* . Page will be auto refresh after 1 seconds as follows.
response.setIntHeader("Refresh", 1);
To get the Current Time.
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
The java.util.Calendar.getInstance() method gets a calendar using the specified time zone and specified locale. Declaration will be as follows.
public static Calendar getInstance(TimeZone zone,Locale locale)
dateFormat.format(cal.getTime() is used to set the time format.
Output
JSP Auto Refresh – Presently put the above code in index.jsp and attempt to get to it. This would show current framework time after 1 second. Simply run the JSP and hold up to see the outcome as follows.
response.setIntHeader("Refresh", 1);
represent refreshing per 1 second.