javax.servlet
Class GenericServlet
java.lang.Object
javax.servlet.GenericServlet
- Serializable, Servlet, ServletConfig
public abstract class GenericServlet
extends java.lang.Object
Abstract base class for all servlets.
void | destroy() - Called by the server when it no longer needs the servlet.
|
String | getInitParameter(String name) - Gets a servlet's initialization parameter
|
Enumeration | getInitParameterNames() - Gets all the initialization parameters
|
ServletConfig | getServletConfig() - Gets the servlet servletConfig class
|
ServletContext | getServletContext() - Returns the servlets context
|
String | getServletInfo() - The servlet programmer can put other additional info (version
number, etc) here.
|
String | getServletName() - Gets you the name of this servlet's instance.
|
void | init() - Automatically called by
init(ServletConfig servletConfig) .
|
void | init(ServletConfig servletConfig) - Initializes the servlet.
|
void | log(String message) - Writes the class name and a message to the log.
|
void | log(String message, Throwable th) - 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.
|
GenericServlet
public GenericServlet()
Does nothing.
destroy
public void destroy()
Called by the server when it no longer needs the servlet.
The servlet programmer should use this method to free all
the resources the servlet is holding.
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.
- destroy in interface Servlet
getInitParameter
public String getInitParameter(String name)
Gets a servlet's initialization parameter
- getInitParameter in interface ServletConfig
name
- the name of the wanted parameter
- the value of the wanted parameter.
null if the named parameter is not present.
getInitParameterNames
public Enumeration getInitParameterNames()
Gets all the initialization parameters
- getInitParameterNames in interface ServletConfig
- an Enumeration of all the parameters
getServletInfo
public String getServletInfo()
The servlet programmer can put other additional info (version
number, etc) here.
The Servlet 2.1 Spec says that this should return an empty string.
The Servlet 2.1 API says that this should return null unless overridden.
This version returns the servlet's class name which seems more usefull.
- getServletInfo in interface Servlet
- The String holding the information
getServletName
public String getServletName()
Gets you the name of this servlet's instance.
Calls its servletConfig's getServletName.
- getServletName in interface ServletConfig
init
public void init()
throws ServletException
Automatically called by init(ServletConfig servletConfig)
.
This version does nothing.
init
public void init(ServletConfig servletConfig)
throws ServletException
Initializes the servlet.
Called by the server exactly once during the lifetime of the servlet.
This method can be used to setup resources (connections to a
database for example) for this servlet.
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(servletConfig)
otherwise the other methods in
GenericServlet are not garanteed to work.
- init in interface Servlet
servletConfig
- This servlet configuration class
log
public void log(String message)
Writes the class name and a message to the log.
Calls getServletContext().log()
.
message
- the message to write
log
public void log(String message,
Throwable th)
Writes the class name, a message and a stack trace to the log.
Calls getServletContext().log()
.
message
- the message to writeth
- the object that was thrown to cause this log
service
public abstract void service(ServletRequest request,
ServletResponse response)
throws ServletException,
IOException
Called by the server every time it wants the servlet to handle
a request.
- service in interface Servlet
request
- all the request informationresponse
- class to write all the response data to