4

I am not quite sure of the significance of the following piece of code. It seems that it might cause the page to refresh automatically at some given interval. However, this is just a guess. How is this "Refresh" parameter used? Any other explanation is appreciated. I have done some googling/looked at documentation to no avail.

// I have some instance of HttpServletRepsonse named response
response.setHeader("Refresh","300");
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
well actually
  • 11,810
  • 19
  • 52
  • 70

7 Answers7

4

That's the HTTP refresh header which is better known as the meta refresh tag. The one in your question is the HTTP response header equivalent of the following line in HTML <head>:

<meta http-equiv="refresh" content="300" />

It will reload the current request after the given amount of seconds, as if you're pressing F5. It was an old Netscape invention and supported by most if not all browsers, but this "meta" header is not taken into the RFC 2616 - HTTP header field definitions standard. The W3C also discourages the use of this header.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 2
    This isn't the same thing as a meta tag. This is merely a "Refresh" header. – Will Chesterfield Oct 24 '11 at 18:00
  • @Will: I didn't mean to say that they're the same, more that the purpose is better known to be achieved by the HTML meta tag. You can represent all HTTP response headers by HTML meta `http-equiv` tags. Only when an equivalent is already present in the HTTP response header, then the meta tag is ignored. However, the meta tag is always been used when the HTML resource is been opened from for example the local disk file system instead of by a HTTP request (e.g. after you save the page to disk). – BalusC Oct 24 '11 at 18:04
  • Should refresh header preserve the part after the #? When I click on a link in FB post, the resultant redirect contains a `Refresh` header with `URL` containing #, but when the browser redirects, it is requesting without the hash. – Nikhil Sahu Jan 23 '19 at 12:48
2

You didn't search very hard. See http://en.wikipedia.org/wiki/URL_redirection#Refresh_Meta_tag_and_HTTP_refresh_header. The refresh header is used to ask the browser to redirect to another URL after some delay. I guess it redirects to the same URL if no URL is provided.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
1

response.setHeader(...) adds an HTTP header to the response. These headers are interpreted by web browsers. You can find a list of valid headers in http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

The one in your code "...proprietary, non-standard header introduced by Netscape". This header is the equivalent to meta "refresh" which automatically refreshes the current web page after the given interval

Marc Nuri
  • 2,729
  • 1
  • 14
  • 18
0
response.setIntHeader("refresh", 5);

it gives you the functionality to refresh the page after 5 second.

and also meta refresh tag to use achieve this functionality.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
0

setHeader() is method of Servlet response object to set HTTP response header. refresh is HTTP response header ...so we use response.setHeader("refresh","5"); it will auto refresh the page at interval of 5 second..

0

Wikipedia explains it pretty well: http://en.wikipedia.org/wiki/URL_redirection#Refresh_Meta_tag_and_HTTP_refresh_header

Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103
0

This is an old HTTP header value which has become something of a "standard by convention."

See: 'Refresh' HTTP header

Community
  • 1
  • 1
Will Chesterfield
  • 1,780
  • 12
  • 15