Class GenericServlet
java.lang.Object
javax.servlet.GenericServlet
- All Implemented Interfaces:
Serializable,Servlet,ServletConfig
- Direct Known Subclasses:
HttpServlet
Abstract base class for all servlets.
- Since:
- Servlet API 1.0
- Version:
- Servlet API 2.2
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Called by the server when it no longer needs the servlet.getInitParameter(String name) Gets a servlet's initialization parameterGets all the initialization parametersGets the servlet servletConfig classReturns the servlets contextThe servlet programmer can put other additional info (version number, etc) here.Gets you the name of this servlet's instance.voidinit()Automatically called byinit(ServletConfig servletConfig).voidinit(ServletConfig servletConfig) Initializes the servlet.voidWrites the class name and a message to the log.voidWrites the class name, a message and a stack trace to the log.abstract voidservice(ServletRequest request, ServletResponse response) Called by the server every time it wants the servlet to handle a request.
-
Constructor Details
-
GenericServlet
public GenericServlet()Does nothing.- Since:
- Servlet API 1.0
-
-
Method Details
-
init
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 overrideinit(). Note that if a servlet overrides this method it should callsuper.init(servletConfig)otherwise the other methods in GenericServlet are not garanteed to work.- Specified by:
initin interfaceServlet- Parameters:
servletConfig- This servlet configuration class- Throws:
ServletException- If an error occurs- Since:
- Servlet API 1.0
- See Also:
-
init
Automatically called byinit(ServletConfig servletConfig). This version does nothing.- Throws:
ServletException- If an error occurs- Since:
- Servlet API 2.1
-
getServletContext
Returns the servlets context- Specified by:
getServletContextin interfaceServletConfig- Returns:
- The context
- Since:
- Servlet API 1.0
-
getInitParameter
Gets a servlet's initialization parameter- Specified by:
getInitParameterin interfaceServletConfig- Parameters:
name- the name of the wanted parameter- Returns:
- the value of the wanted parameter. null if the named parameter is not present.
- Since:
- Servlet API 1.0
-
getInitParameterNames
Gets all the initialization parameters- Specified by:
getInitParameterNamesin interfaceServletConfig- Returns:
- an Enumeration of all the parameters
- Since:
- Servlet API 1.0
-
log
Writes the class name and a message to the log. CallsgetServletContext().log().- Parameters:
message- the message to write- Since:
- Servlet API 1.0
-
log
-
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.
- Specified by:
getServletInfoin interfaceServlet- Returns:
- The String holding the information
- Since:
- Servlet API 1.0
-
getServletConfig
Gets the servlet servletConfig class- Specified by:
getServletConfigin interfaceServlet- Returns:
- The servletConfig class
- Since:
- Servlet API 1.0
-
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.- Specified by:
servicein interfaceServlet- Parameters:
request- all the request informationresponse- class to write all the response data to- Throws:
ServletException- If an error occursIOException- If an error occurs- Since:
- Servlet API 1.0
- See Also:
-
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.
-
getServletName
Gets you the name of this servlet's instance. Calls its servletConfig's getServletName.- Specified by:
getServletNamein interfaceServletConfig
-