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

8.4 Creating an HTTP Response

The servlet container provides several ways to use a rwsf::HttpServletResponse object to return a response to a client.

8.4.1 Using Java-Like Output Functions

Each response object contains an output object that supports a set of overloaded print() and println() functions described in the Servlet Specification. These functions are convenient for programmers accustomed to Java servlet programming. The sample below shows a doGet function that creates a simple HTML response with the Java-like functions:

//1

Sets the Content-Type of the response to text/html. A client may use the Content-Type to determine the kind of document in the response. Without this line, some clients interpret the response as plain text.

//2

Gets the output stream from the response.

//3

Prints a line of the response to the client. In this version, the servlet prints the string to the client using the Java-like function println().

8.4.2 Setting the Response from a String

An rwsf::ServletResponse also provides a setPayload() function. The function sets the body of the response directly, from a single string. Setting the payload directly is generally more efficient than using the rwsf::ServletOutputStream class to write the response. The doGet() function below constructs a string, then uses the setPayload() function to create the response.

//1

Sets the Content-Type of the response to text/html. A client may use the Content-Type to determine the kind of document in the response. Without this line, some clients interpret the response as plain text rather than HTML.

//2

Creates an string containing the response.

//3

Sets the content of the response to output. In this version, the servlet sets the entire response in a single operation.

The related function appendPayload() appends a string to the current contents of the response.



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.