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

3.4 Implementing Request Handlers

Request handlers are the functions that handle the client request and construct a response. The servlet base classes define the request handler functions. A derived servlet implements the function or functions that handle the client request.

rwsf::HttpServlet contains default implementations of the handlers for standard HTTP requests.

For HTTP/1.1, the default implementation of most methods return the HTTP Method Not Allowed status code (405) with an appropriate message. The method doHead() first defaults to doGet() before returning status code 405.

For HTTP/1.0, requests return a Bad Request Response status code (400).

An HTTP servlet implements the functions for the methods the servlet accepts and relies on the default implementations for methods the servlet does not accept.

Table 1: Request handlers by HTTP method

HTTP Methodrwsf::HttpServlet functionDescription



Removes the resource from the Agent.



Returns a document.



Returns the headers for a document.



Sends information to the Agent.



Uploads a file to the Agent.



Returns the request to the client

Each of the above functions takes a rwsf::HttpServletRequest and a rwsf::HttpServletResponse as parameters. To respond to a request, a servlet overrides the functions that correspond to the request methods the servlet accepts. For example, an HTTP servlet that accepts the HTTP GET method implements the doGet() function.

Since the HelloWorldExample servlet only responds to HTTP GET requests, the servlet only declares doGet(). The sample below shows an excerpt from the header file for the HelloWorldExample servlet:

The HelloWorldExample servlet does not dynamically allocate resources, so the servlet needs no init() method or destroy() method.

The implementation of the servlet simply returns an HTTP response without inspecting the request. The sample below shows the servlet implementation:

//1Defines servlet HelloWorldExample for the container. The RWSF_DEFINE_SERVLET macro expands to the code the container needs to load the servlet. Each servlet must be defined for the container as described in Section 6.5.
//2Sets the Content-Type of the response to "text/html". By default, a servlet response does not contain a Content-Type header. Since this servlet returns an HTML response, the servlet sets the Content-Type accordingly.
//3Gets a reference to the output stream for the response. The class also provides print() and println() functions that mimic the Java methods.
//4Writes a line of the response. This servlet uses the println() function to demonstrate the similarity between a C++ servlet and a Java servlet.

Previous fileTop of DocumentContentsIndex pageNext file

©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.