In this tutorial you will learn about setDateHeader() method of HttpServletResponse interface.
JSP Response setDateHeader
In this tutorial you will learn about setDateHeader() method of HttpServletResponse interface.
HttpServletResponse setDateHeader() method is used to set date with the specified header name. Using this method in the header date value can be associated with the header name. New value of header will be overwrites if it is already been set.
Syntax :
void setDateHeader(java.lang.String name, long date)
First argument specifies the name of header and the second argument is a date value.
Example :
In this example I have created a JSP page where wrote the code for adding the date header to the response. I have written the code to set date header to the response using the JSP scriptlets. In the first line of code gets a date value and in the next line of code set the date header to the response and then in the next and final line get the header that we have set now.
jspSetDateHeader.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 Response setDateHeader</title> </head> <body> <% long date = new Date().getTime(); response.setDateHeader("Date", date); out.println("Date : "+response.getHeader("Date")); %> </body> </html>
Output :
When you will execute the example you will get the output as follows :
[ 0 ] Comments