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 a 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 by calling encodeRedirectURL() on the response:

Note that the sendRedirect() function sends an HTTP redirect message to the client.



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo are registered trademarks of Rogue Wave Software, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.