public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
Constructor and Description |
---|
GenericServlet()
Does nothing.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Called by the server when it no longer needs the servlet.
|
java.lang.String |
getInitParameter(java.lang.String name)
Gets a servlet's initialization parameter
|
java.util.Enumeration |
getInitParameterNames()
Gets all the initialization parameters
|
ServletConfig |
getServletConfig()
Gets the servlet config class
|
ServletContext |
getServletContext()
Returns the servlets context
|
java.lang.String |
getServletInfo()
The servlet programmer can put other additional info (version
number, etc) here.
|
java.lang.String |
getServletName()
Gets you the name of this servlet's instance.
|
void |
init()
Automatically called by
init(ServletConfig config) . |
void |
init(ServletConfig config)
Initializes the servlet.
|
void |
log(java.lang.String message)
Writes the class name and a message to the log.
|
void |
log(java.lang.String message,
java.lang.Throwable throwable)
Writes the class name, a message and a stack trace to the log.
|
abstract void |
service(ServletRequest request,
ServletResponse response)
Called by the server every time it wants the servlet to handle
a request.
|
public void destroy()
This version does nothing because it has nothing to clean up.
Note that the the 2.1 Spec says that this should do nothing, but the 2.1 API Doc says that it logs the destroy action.
public java.lang.String getInitParameter(java.lang.String name)
getInitParameter
in interface ServletConfig
name
- the name of the wanted parameterpublic java.util.Enumeration getInitParameterNames()
getInitParameterNames
in interface ServletConfig
public ServletConfig getServletConfig()
getServletConfig
in interface Servlet
public ServletContext getServletContext()
getServletContext
in interface ServletConfig
public java.lang.String getServletInfo()
getServletInfo
in interface Servlet
public void init(ServletConfig config) throws ServletException
This version saves the ServletConfig and calls init()
.
This means that a servlet can just override init()
.
Note that if a servlet overrides this method it should call
super.init(config)
otherwise the other methods in
GenericServlet are not garanteed to work.
init
in interface Servlet
config
- This servlet configuration classServletException
- If an error occursUnavailableException
public void init() throws ServletException
init(ServletConfig config)
.
This version does nothing.ServletException
- If an error occurspublic void log(java.lang.String message)
getServletContext().log()
.message
- the message to writepublic void log(java.lang.String message, java.lang.Throwable throwable)
getServletContext().log()
.message
- the message to writethrowable
- the object that was thrown to cause this logpublic abstract void service(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
service
in interface Servlet
request
- all the request informationresponse
- class to write all the response data toServletException
- If an error occursjava.io.IOException
- If an error occursSingleThreadModel
public java.lang.String getServletName()
getServletName
in interface ServletConfig