[ Team LiB ] Previous Section Next Section

Recipe 18.5 Automatically Refreshing a JSP

Problem

You want to refresh a JSP request at a specified interval.

Solution

Use a JSP scriptlet that adds a Refresh response header to the response.

Discussion

The following scriptlet code adds a Refresh header that specifies a 60-second interval for refreshing the JSP. Place this code at the top of the JSP before any content appears:

<% response.addHeader("Refresh","60"); %>

If you want to refresh the JSP to another web component or page, use this syntax:

<% response.addHeader("Refresh","10;
  http://localhost:8080/home/thanks.jsp"); %>

See Also

Example 18-6 in Recipe 18.4 on refreshing a servlet; Example 18-7 in Recipe 18.4 on limiting the number of automatic refreshes of a servlet; Recipe 18.1 and Recipe 18.2 on examining request headers in a servlet and a JSP, respectively; Recipe 18.3 on using a filter to wrap the request and forward it along the filter chain; Recipe 18.6 on using a listener to track requests.

    [ Team LiB ] Previous Section Next Section