Bitcoin

Bitcoin
Bitcoin

JSP - Auto Page Refresh

JSP makes this job easy by providing you a mechanism where you can make a webpage in such a way that it would refresh automatically after a given interval.
The simplest way of refreshing a Webpage is by using the setIntHeader()method of the response object. Following is the signature of this method −

Syntax

public void setIntHeader(String header, int headerValue)
This method sends back the header "Refresh" to the browser along with an integer value which indicates time interval in seconds.

Auto Page Refresh Example

<%@ page import="java.io.*,java.text.*,java.util.*"%>
<html>

<head>
<title>Auto Refresh Header Example</title>
</head>

<body>
<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()));
%>
</body>
</html>

No comments:

Post a Comment

Facebook