java.lang.Object | +--javax.servlet.GenericServlet
Defines a generic, protocol-independent servlet. To write an HTTP servlet for use on the Web, extendHttpServlet
instead.
GenericServlet
implements theServlet
andServletConfig
interfaces.GenericServlet
may be directly extended by a servlet, although it's more common to extend a protocol-specific subclass such asHttpServlet
.
GenericServlet
makes writing servlets easier. It provides simple versions of the lifecycle methodsinit
anddestroy
and of the methods in theServletConfig
interface.GenericServlet
also implements thelog
method, declared in theServletContext
interface.
To write a generic servlet, you need only override the abstractservice
method.
GenericServlet() Does nothing. |
destroy() Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. | |
getInitParameter(java.lang.String name) Returns a String containing the value of the named initialization parameter, ornull if the parameter does not exist. | |
getInitParameterNames() Returns the names of the servlet's initialization parameters as an Enumeration ofString objects, or an emptyEnumeration if the servlet has no initialization parameters. | |
getServletConfig() Returns this servlet's ServletConfig object. | |
getServletContext() Returns a reference to the ServletContext in which this servlet is running. | |
getServletInfo() Returns information about the servlet, such as author, version, and copyright. | |
getServletName() Returns the name of this servlet instance. | |
init() A convenience method which can be overridden so that there's no need to call super.init(config) . | |
init(ServletConfig config) Called by the servlet container to indicate to a servlet that the servlet is being placed into service. | |
log(java.lang.String msg) Writes the specified message to a servlet log file, prepended by the servlet's name. | |
log(java.lang.String message, java.lang.Throwable t) Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file, prepended by the servlet's name. | |
service(ServletRequest req,ServletResponse res) Called by the servlet container to allow the servlet to respond to a request. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
publicGenericServlet()
init
methods.public voiddestroy()
Servlet.destroy()
.destroy
in interfaceServlet
public java.lang.StringgetInitParameter(java.lang.String name)
String
containing the value of the named initialization parameter, ornull
if the parameter does not exist. SeeServletConfig.getInitParameter(java.lang.String)
.This method is supplied for convenience. It gets the value of the named parameter from the servlet'sServletConfig
object.
getInitParameter
in interfaceServletConfig
name
- aString
specifying the name of the initialization parameterString
containing the valueof the initalization parameterpublic java.util.EnumerationgetInitParameterNames()
Enumeration
ofString
objects, or an emptyEnumeration
if the servlet has no initialization parameters. SeeServletConfig.getInitParameterNames()
.This method is supplied for convenience. It gets the parameter names from the servlet'sServletConfig
object.
getInitParameterNames
in interfaceServletConfig
String
objects containing the names of the servlet's initialization parameterspublicServletConfiggetServletConfig()
ServletConfig
object.getServletConfig
in interfaceServlet
ServletConfig
objectthat initialized this servletpublicServletContextgetServletContext()
ServletContext
in which this servlet is running. SeeServletConfig.getServletContext()
.This method is supplied for convenience. It gets the context from the servlet'sServletConfig
object.
getServletContext
in interfaceServletConfig
ServletContext
objectpassed to this servlet by theinit
methodpublic java.lang.StringgetServletInfo()
Servlet.getServletInfo()
.getServletInfo
in interfaceServlet
public voidinit(ServletConfig config) throwsServletException
Servlet.init(javax.servlet.ServletConfig)
.This implementation stores theServletConfig
object it receives from the servlet container for later use. When overriding this form of the method, callsuper.init(config)
.
init
in interfaceServlet
config
- theServletConfig
objectthat contains configutationinformation for this servletServletException
- if an exception occurs thatinterrupts the servlet's normaloperationUnavailableException
public voidinit() throwsServletException
super.init(config)
.Instead of overridinginit(ServletConfig)
, simply override this method and it will be called byGenericServlet.init(ServletConfig config)
. TheServletConfig
object can still be retrieved viagetServletConfig()
.
ServletException
- if an exception occurs thatinterrupts the servlet'snormal operationpublic voidlog(java.lang.String msg)
ServletContext.log(String)
.msg
- aString
specifyingthe message to be written to the log filepublic voidlog(java.lang.String message, java.lang.Throwable t)
Throwable
exception to the servlet log file, prepended by the servlet's name. SeeServletContext.log(String, Throwable)
.message
- aString
that describesthe error or exceptiont
- thejava.lang.Throwable
error or exceptionpublic abstract voidservice(ServletRequest req,ServletResponse res) throwsServletException, java.io.IOException
Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
.This method is declared abstract so subclasses, such asHttpServlet
, must override it.
service
in interfaceServlet
req
- theServletRequest
objectthat contains the client's requestres
- theServletResponse
objectthat will contain the servlet's responseServletException
- if an exception occurs thatinterferes with the servlet'snormal operation occurredjava.io.IOException
- if an input or outputexception occurspublic java.lang.StringgetServletName()
ServletConfig.getServletName()
.getServletName
in interfaceServletConfig