JSP Auto Refresh



JSP Auto Refresh :

  1. Suppose we need to refresh the web page automatically after some time then we can use JSP setIntHeader() method.
  2. We need auto refresh of page while displaying the Cricket Score or Stock Market Status
  3. setIntHeader() method is used to set the value of the specified header.
  4. “Refresh” is a predefined response header name which is a proprietary non-standard header extension, instruct the browser to update/refresh the page in seconds.
  5. Below is the Syntax of JSP setIntHeader() method –

Syntax :

public void setIntHeader(String header, int headerValue)

Above method is used to send header “Refresh” to the browser. Integer value 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>

Output :

Auto Refresh Header