The servlet interface is designed to make creating Web applications an easy and intuitive process. This chapter explains the process of creating a servlet and presents the code for a simple servlet.
The HydraExpress servlet container instantiates the servlet when it starts, then calls the init() method on the servlet. Each time a client request arrives, the servlet container calls a handler method on the servlet. Before the container shuts down, it calls the destroy() method on the servlet. This chapter covers the steps required to define, implement, compile, and deploy a complete servlet. Although the servlet described is simple, the example presents all the basic tasks necessary to write a servlet.
The servlet described in this section is included in the files HelloWorldExample.h and HelloWorldExample.cpp in the tutorials\servlet directory of the HydraExpress installation. The servlet itself is available at http://localhost:8090/examples/HelloWorldExample on a system running HydraExpress.
Creating and deploying a servlet involves the following steps:
Create a class that inherits from rwsf::HttpServlet. This class provides the basic framework for a C++ servlet (Section 3.2)
Define the servlet by using the RWSF_DEFINE_SERVLET macro within a single source file (Section 3.3)
Implement the request handlers (Section 3.4)
Compile the servlet into a shared library (Section 3.5)
Copy the shared library into the path that the system uses to load shared libraries (Section 3.6)
Add the servlet deployment descriptor to the web.xml file in the servlet context (Section 3.7)
If the servlet resides in a new context, configure any external Web servers to forward requests to the new context. Section 4.12 describes the process of reconfiguring the Web server.
Stop and restart the HydraExpress Agent (Section 3.8).
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.