Following is an example for JSP Auto Refresh.
index.jsp
[html]<%@ 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="http://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>[/html]
Here just imported the packages such as
java.io.*,
java.text.*,
java.util.* . Page will be auto refresh after 1 seconds as follows.
[java]response.setIntHeader("Refresh", 1);[/java]
To get the Current Time.
[java]DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");[/java]
The
java.util.Calendar.getInstance() method gets a calendar using the specified time zone and specified locale. Declaration will be as follows.
[java]public static Calendar getInstance(TimeZone zone,Locale locale)[/java]
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.