JSP Response getHeader

JSP Response getHeader


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

In this tutorial you will learn about the getHeader() method of HttpServletResponse interface.

JSP Response getHeader

In this tutorial you will learn about the getHeader() method of HttpServletResponse interface.

HttpServletResponse interface provides the facility to get the value of the header that are associated with the header names. Header value should be associated with the header name using the setter method or adder method provided by this interface.

Syntax :

java.lang.String getHeader(java.lang.String name)

Argument of this method is a name of header of which you want to get the value. This method returns the value of the specified header name or null if the header is not specified.

Example :

An example is being given here will demonstrate you about how to get the value of the header associated with the corresponding header name. In this example I have created a JSP page where wrote the code for getting the value of the header that are set/added using setHeader() and addHeader() method.

jspGetHeader.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="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 Response getHeader</title>
</head>
<body>
<%
Date date = new Date();
Format formatter= new SimpleDateFormat("dd.MM.yyyy.HH.mm.ss");
String newDate = formatter.format(date);
response.setHeader("Refresh", "1");
response.addHeader("Date", newDate);
out.println("Date & Time : "+ response.getHeader("Date")+"<br>");
out.println("Page Refresh/sec : "+response.getHeader("Refresh"));
out.close();

%>
</body>
</html>

Output :

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

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics