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:
void myServlet::doGet (rwsf::HttpServletRequest& request,
rwsf::HttpServletResponse& response)
response.setContentType("text/html"); // 1
rwsf::ServletOutputStream& out = response.getOutputStream(); // 2
out.println("<html>"); // 3
out.println("<head><title>Simple Response</title></head>");
out.println("<body bgcolor=\"white\">");
out.println("<h1>Simple Response</h1>");
out.println("A simple HTML 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.
//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().