JSP Response setIntHeader

JSP Response setIntHeader


Posted in : Java Posted on : May 11, 2012 at 6:11 PM Comments : [ 0 ]

In this tutorial you will learn about how to use setIntHeader() method.

JSP Response setIntHeader

In this tutorial you will learn about how to use setIntHeader() method.

HttpServletResponse interface provides a method setIntHeader() to set an integer value to the response header. This method sets the integer value with their corresponding name of header. This method overwrites the new value if the value of the specified header has already set.

Syntax :

void setIntHeader(java.lang.String name, int value)

First argument of this method specifies the name of header and the second one specifies its corresponding value.

Example :

In the example given below is illustrating the use of setIntHeader() method as well as it also explains how to refresh a JSP page after a specified time. In this example I have created a JSP page where used the setIntHeader() method to set the value of the specified header. In the header name I have used "Refresh" this is a predefined response header name which is a proprietary non-standard header extension, instruct the browser to update/refresh the page in seconds. To focus on refreshing that occurs in a specified time I have used the Date class to display the date. In this example on a web page date will be displayed in this format "dd.MM.yyyy.HH.mm.ss" i.e. (day.month.year.hour.minute.second).

jspResponseSetIntHeader.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*,java.util.*, java.text.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Auto Refresh page</title>
</head>
<body>
<h2>Auto Refresh Header Example</h2>
<%
// Set refresh, autoload time as 1 seconds
response.setIntHeader("Refresh", 1);
Format formatter= new SimpleDateFormat("dd.MM.yyyy.HH.mm.ss");
Date date = new Date();
String newDate = formatter.format(date);
out.println(newDate);

%>
</body>
</html>

Output :

When you will execute the above JSP page an output will be as follows :

This page will automatically refreshed in every second.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics