Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress Servlet Development Guide

8.6 Returning an Error

rwsf::HttpServletResponse provides the function sendError() for returning an error to the client. The function takes an HTTP status code, and an optional std::string containing the payload of the error message. The code sample below sets the response to a Service Unavailable error, and suggests that the client try again in 10 minutes (600 seconds).

Notice that the sample uses an enum from class rwsf::HttpServletResponse for the status code. rwsf::HttpServletResponse provides values for the status codes defined by HTTP 1.1. See the HydraExpress C++ API Reference Guide for details.

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

Errors returning from a servlet follow the standard error handling process. If the current context declares an error-page for the error code, the servlet container forwards the request to that resource. Otherwise, if the global web.xml file contains an error-page for the error code, the container forwards the request to the resource declared in the global web.xml file. If neither web.xml file declares an error-page, the container returns the response directly to the client.



Previous fileTop of DocumentContentsNo linkNext 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.
Provide feedback to Rogue Wave about its documentation.