Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress Servlet Development Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

8.7 Redirecting the Client

The response object provides a function for returning an HTTP redirect. The sendRedirect() function takes an string containing a URL, and sets the response to an HTTP Temporary Redirect directing the client to the URL. The code sample below redirects a client to the Rogue Wave Web site:

The Servlet Specification allows the servlet container to transmit the response to the client as soon as the servlet calls sendRedirect(). Therefore, the servlet should not alter the response after calling sendRedirect(), since the client may not receive the changes.

The sendRedirect() function does not rewrite the URL to include session information. If the servlet uses URL rewriting to track sessions, the servlet should rewrite the URL before calling sendRedirect(). The sample below forwards the client to another servlet in the same context while preserving session information:

Note that the sendRedirect() function sends an HTTP redirect message to the client. A servlet can also directly retrieve content from another location, or forward a request to another servlet in the container. For details on forwarding a request, see Section 8.8.



Previous fileTop of DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.