#include <GenericServlet.h>
Public Member Functions | |
GenericServlet () | |
virtual | ~GenericServlet () |
virtual void | destroy () |
virtual std::string | getInitParameter (const std::string &name) const |
virtual std::auto_ptr < std::vector< std::string > > | getInitParameterNames () const |
virtual ServletConfig & | getServletConfig () const |
virtual ServletContext & | getServletContext () const |
virtual std::string | getServletInfo () const |
virtual void | init (ServletConfig &config) |
virtual void | init () |
virtual void | log (const std::string &msg) |
virtual void | log (const std::string &message, const std::exception &e) |
virtual void | service (ServletRequest &req, ServletResponse &res)=0 |
virtual std::string | getServletName () const |
Private Attributes | |
ServletConfig * | config |
GenericServlet
implements the Servlet
and ServletConfig
interfaces. GenericServlet
may be directly extended by a servlet, although it's more common to extend a protocol-specific subclass such as HttpServlet
.
GenericServlet
makes writing servlets easier. It provides simple versions of the lifecycle methods init
and destroy
and of the methods in the ServletConfig
interface. GenericServlet
also implements the log
method, declared in the ServletContext
interface.
To write a generic servlet, you need only override the abstract service
method.
Definition at line 98 of file GenericServlet.h.
servlet::GenericServlet::GenericServlet | ( | ) |
Does nothing. All of the servlet initialization is done by one of the init
methods.
Definition at line 62 of file GenericServlet.cpp.
virtual servlet::GenericServlet::~GenericServlet | ( | ) | [inline, virtual] |
Definition at line 110 of file GenericServlet.h.
void servlet::GenericServlet::destroy | ( | ) | [virtual] |
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. See servlet::Servlet#destroy.
Implements servlet::Servlet.
Definition at line 66 of file GenericServlet.cpp.
virtual std::string servlet::GenericServlet::getInitParameter | ( | const std::string & | name | ) | const [virtual] |
Returns a String
containing the value of the named initialization parameter, or null
if the parameter does not exist. See servlet::ServletConfig#getInitParameter.
This method is supplied for convenience. It gets the value of the named parameter from the servlet's ServletConfig
object.
name | a String specifying the name of the initialization parameter |
String
containing the value of the initialization parameter Implements servlet::ServletConfig.
auto_ptr< vector< string > > servlet::GenericServlet::getInitParameterNames | ( | ) | const [virtual] |
Returns the names of the servlet's initialization parameters as an Enumeration
of String
objects, or an empty Enumeration
if the servlet has no initialization parameters. See servlet::ServletConfig#getInitParameterNames.
This method is supplied for convenience. It gets the parameter names from the servlet's ServletConfig
object.
String
objects containing the names of the servlet's initialization parameters Implements servlet::ServletConfig.
Definition at line 75 of file GenericServlet.cpp.
References servlet::ServletConfig::getInitParameterNames(), and getServletConfig().
ServletConfig & servlet::GenericServlet::getServletConfig | ( | ) | const [virtual] |
Returns this servlet's servlet::ServletConfig object.
servlet::ServletConfig
object that initialized this servlet Definition at line 81 of file GenericServlet.cpp.
References config.
Referenced by getInitParameterNames(), and getServletContext().
ServletContext & servlet::GenericServlet::getServletContext | ( | ) | const [virtual] |
Returns a reference to the servlet::ServletContext in which this servlet is running. See servlet::ServletConfig#getServletContext.
This method is supplied for convenience. It gets the context from the servlet's ServletConfig
object.
ServletContext
object passed to this servlet by the init
method Implements servlet::ServletConfig.
Definition at line 87 of file GenericServlet.cpp.
References getServletConfig(), and servlet::ServletConfig::getServletContext().
string servlet::GenericServlet::getServletInfo | ( | ) | const [virtual] |
Returns information about the servlet, such as author, version, and copyright. By default, this method returns an empty string. Override this method to have it return a meaningful value. See servlet::Servlet#getServletInfo.
Implements servlet::Servlet.
Definition at line 93 of file GenericServlet.cpp.
string servlet::GenericServlet::getServletName | ( | ) | const [virtual] |
Returns the name of this servlet instance. See servlet::ServletConfig#getServletName.
Implements servlet::ServletConfig.
Definition at line 122 of file GenericServlet.cpp.
References config, and servlet::ServletConfig::getServletName().
void servlet::GenericServlet::init | ( | ) | [virtual] |
A convenience method which can be overridden so that there's no need to call super.init(config)
.
Instead of overriding init(servlet::ServletConfig&), simply override this method and it will be called by GenericServlet.init(servlet::ServletConfig& config)
. The ServletConfig
object can still be retrieved via getServletConfig.
servlet::ServletException | if an exception occurs that interrupts the servlet's normal operation |
Definition at line 105 of file GenericServlet.cpp.
Referenced by init().
void servlet::GenericServlet::init | ( | ServletConfig & | config | ) | [virtual] |
Called by the servlet container to indicate to a servlet that the servlet is being placed into service. See servlet::Servlet#init.
This implementation stores the servlet::ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config)
.
config | the ServletConfig object that contains configutation information for this servlet |
ServletException | if an exception occurs that interrupts the servlet's normal operation |
Implements servlet::Servlet.
Definition at line 98 of file GenericServlet.cpp.
References init().
virtual void servlet::GenericServlet::log | ( | const std::string & | message, | |
const std::exception & | e | |||
) | [virtual] |
Writes an explanatory message and a stack trace for a given std::exception
exception to the servlet log file, prepended by the servlet's name. See servlet::ServletContext#log(const std::string& msg, std::exception& e).
message | a std::string that describes the error or exception | |
e | the std::exception error or exception |
virtual void servlet::GenericServlet::log | ( | const std::string & | msg | ) | [virtual] |
Writes the specified message to a servlet log file, prepended by the servlet's name. See servlet::ServletContext#log(const std::string& msg).
msg | an std::string specifying the message to be written to the log file |
virtual void servlet::GenericServlet::service | ( | ServletRequest & | req, | |
ServletResponse & | res | |||
) | [pure virtual] |
Called by the servlet container to allow the servlet to respond to a request. See servlet::Servlet#service.
This method is declared abstract so subclasses, such as HttpServlet
, must override it.
req | the ServletRequest object that contains the client's request | |
res | the ServletResponse object that will contain the servlet's response |
ServletException | if an exception occurs that interferes with the servlet's normal operation occurred | |
IOException | if an input or output exception occurs |
Implements servlet::Servlet.
Implemented in servlet::HttpServlet.
ServletConfig* servlet::GenericServlet::config [private] |
Definition at line 99 of file GenericServlet.h.
Referenced by getServletConfig(), and getServletName().