Class: javax.servlet.GenericServlet
- public abstract class GenericServlet
- implements Servlet, ServletConfig, java.io.Serializable
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.
Methods
-
GenericServlettop
public GenericServlet()Does nothing. All of the servlet initialization is done by one of theinitmethods. -
destroytop
public void destroy()Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. See javax.servlet.Servlet.destroy(). -
getInitParametertop
Returns aStringcontaining the value of the named initialization parameter, ornullif the parameter does not exist. See javax.servlet.ServletConfig.getInitParameter(java.lang.String).This method is supplied for convenience. It gets the value of the named parameter from the servlet's
ServletConfigobject.- Specified by:
- getInitParameter from ServletConfig
-
getInitParameterNamestop
public Enumeration getInitParameterNames()Returns the names of the servlet's initialization parameters as anEnumerationofStringobjects, or an emptyEnumerationif the servlet has no initialization parameters. See javax.servlet.ServletConfig.getInitParameterNames().This method is supplied for convenience. It gets the parameter names from the servlet's
ServletConfigobject.- Specified by:
- getInitParameterNames from ServletConfig
-
getServletConfigtop
public ServletConfig getServletConfig()Returns this servlet's javax.servlet.ServletConfig object.- Specified by:
- getServletConfig from Servlet
-
getServletContexttop
public ServletContext getServletContext()Returns a reference to the javax.servlet.ServletContext in which this servlet is running. See javax.servlet.ServletConfig.getServletContext().This method is supplied for convenience. It gets the context from the servlet's
ServletConfigobject.- Specified by:
- getServletContext from ServletConfig
-
getServletInfotop
public String getServletInfo()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 javax.servlet.Servlet.getServletInfo().- Specified by:
- getServletInfo from Servlet
-
getServletNametop
public String getServletName()Returns the name of this servlet instance. See javax.servlet.ServletConfig.getServletName().- Specified by:
- getServletName from ServletConfig
-
inittop
public void init() throws ServletExceptionA convenience method which can be overridden so that there's no need to callsuper.init(config).Instead of overriding javax.servlet.GenericServlet.init(javax.servlet.ServletConfig), simply override this method and it will be called by
GenericServlet.init(ServletConfig config). TheServletConfigobject can still be retrieved via javax.servlet.GenericServlet.getServletConfig(). -
inittop
public void init(ServletConfig config) throws ServletExceptionCalled by the servlet container to indicate to a servlet that the servlet is being placed into service. See javax.servlet.Servlet.init(javax.servlet.ServletConfig).This implementation stores the javax.servlet.ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call
super.init(config). -
logtop
public void log(String msg)Writes the specified message to a servlet log file, prepended by the servlet's name. See javax.servlet.ServletContext.log(java.lang.String). -
logtop
Writes an explanatory message and a stack trace for a givenThrowableexception to the servlet log file, prepended by the servlet's name. See javax.servlet.ServletContext.log(java.lang.String, java.lang.Throwable). -
servicetop
public abstract void service(ServletRequest req, ServletResponse res) throws ServletException, IOExceptionCalled by the servlet container to allow the servlet to respond to a request. See javax.servlet.Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse).This method is declared abstract so subclasses, such as
HttpServlet, must override it.
