Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

URI Redirection and Page Refresh

Two common techniques for improving the Web browsing experience for users are

  • URI redirection—This enables one Web page to send a response asking the browser to automatically fetch a page from a different URI.

  • Page refresh—This is used to ask a browser to load a Web page after a specified delay period (this might be the same or a different URI).

URI Redirection

In Table 3.2 you saw that response error codes of 301 and 307 indicate a page request should be redirected to another URI. Most browsers will resubmit the request using the URI specified in the Location header field of the response.

The URI redirect response is used to permit multiple URIs to refer to the same document without duplicating the document. This can be useful when reorganizing a Web site to ensure that old hypertext links are still valid. Tomcat uses page redirection to map the default root document (/) onto /index.html, as shown in the highlighted lines in this example:

HTTP/1.1 302 Moved Temporarily
Content-Type: text/html
Connection: close
Date: Tue, 02 Apr 2002 14:55:16 GMT
Location: http://localhost:8080/index.html
Server: Apache Tomcat/4.0.2 (HTTP/1.1 Connector)

<html><head><title>Apache Tomcat/4.0.2 - Error report</title>
H1{font-family : sans-serif,Arial,Tahoma;color : white;
  background-color : #0086b2;}
BODY{font-family : sans-serif,Arial,Tahoma;color : black;
  background-color : white;}
B{color : white;background-color : #0086b2;} HR{color : #0086b2;}
--></STYLE> </head><body>
<h1>Apache Tomcat/4.0.2 - HTTP Status 302 - Moved Temporarily</h1>
<HR size="1" noshade><p><b>type</b> Status report</p>
<p><b>message</b> <u>Moved Temporarily</u></p>
<u>The requested resource (Moved Temporarily) has moved temporarily
to a new location.</u></p>
<HR size="1" noshade>

The page body includes a simple notice containing the required redirection URI. If the browser doesn't perform the automatic redirect, the user will see the notice and can manually follow the link to the new URI.

Page Refresh

An alternative technique for asking the browser to load a different URI is an HTML-related feature rather than a standard HTTP feature.

A Web page containing a META tag with the HTTP-EQUIV="refresh" attribute is used to ask a Web browser to load a page after a specified time period. The following HTML tag refreshes the current page after five minutes:

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

The same effect is obtained using the following HTTP response header:

Refresh: 300

The Refresh header is not part of the official HTTP specification, but is recognized by most Web browsers.

Both forms of refreshing can specify a URI to reload after the refresh interval has expired, effectively providing another means of redirecting a client to another URI. This technique can be used to briefly display one page before moving on to another—something the redirect response cannot do because the redirection cannot have a time delay. The following HTTP header shows how to display the current page for 15 seconds before reloading the Web server home page (the new URL is separated from the refresh time by a semicolon):

Refresh: 15;/index.html

This technique of requesting the client to refresh a page after a time delay is known as client pull. Client pull can be a useful technique for ensuring that a Web page maintains up-to-date information, such as that required for stock and share prices provided by an online trading page.


Web pages with short refresh cycles can cause excessive amounts of network traffic and overload a Web server.

  • + Share This
  • 🔖 Save To Your Account