javax.servlet

Class GenericServlet

Implemented Interfaces:
Serializable, Servlet, ServletConfig
Known Direct Subclasses:
HttpServlet

public abstract class GenericServlet
extends Object
implements Servlet, ServletConfig, Serializable

GenericServlet is a convenient abstract class for defining Servlets. Servlets which need more control than HttpServlet can extend GenericServlet.

In addition, GenericServlet implements ServletConfig to make it easier to get configuration information.

Servlet configuration looks like the following:


 <servlet servlet-name='myservlet'
          servlet-class='test.MyServlet'>
   <init-param param1='value1'/>
   <init-param param2='value2'/>
 </servlet>
 
See Also:
Serialized Form

Method Summary

void
destroy()
Called when the servlet (and the application) shuts down.
String
getInitParameter(String name)
Returns an initialization parameter.
Enumeration<E>
getInitParameterNames()
Enumerates all the initialization parameter.
ServletConfig
getServletConfig()
Returns this servlet's configuration.
ServletContext
getServletContext()
Returns the application (servlet context) that the servlet belongs to.
String
getServletInfo()
Returns a string describing the servlet.
String
getServletName()
Returns the servlet name for this configuration.
void
init()
Initialize the servlet.
void
init(ServletConfig config)
Initialize the servlet.
void
log(String message)
Logs an error message in the application's log.
void
log(String message, Throwable cause)
Logs an error message and an exception trace in the application's log.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

destroy

public void destroy()
Called when the servlet (and the application) shuts down.
Specified by:
destroy in interface Servlet

getInitParameter

public String getInitParameter(String name)
Returns an initialization parameter. Initialization parameters are defined in the servlet configuration (in resin.conf) as follows:

 <servlet servlet-name='myservlet'
          servlet-class='test.MyServlet'>
   <init-param param1='value1'/>
   <init-param param2='value2'/>
 </servlet>
 
Specified by:
getInitParameter in interface ServletConfig
Parameters:
name - of the parameter
Returns:
the init parameter value

getInitParameterNames

public Enumeration<E> getInitParameterNames()
Enumerates all the initialization parameter.
Specified by:
getInitParameterNames in interface ServletConfig

getServletConfig

public ServletConfig getServletConfig()
Returns this servlet's configuration.
Specified by:
getServletConfig in interface Servlet

getServletContext

public ServletContext getServletContext()
Returns the application (servlet context) that the servlet belongs to. The application provides several useful methods, e.g. including other files, forwarding, and translating physical paths.
Specified by:
getServletContext in interface ServletConfig
Usages and Demos :

View More Examples of getServletContext()
   1: import javax.servlet.ServletContext;
   2: import javax.servlet.GenericServlet;
   3: import javax.servlet.jsp.JspException;
   4:         ...
   5:     MessageContext mctx = MessageContext.getCurrentContext();
   6:     GenericServlet axis = (GenericServlet)mctx.getProperty("transport.http.servlet");
   7:         ...
   8:     return axis.getServletContext();
   9:   }

View Full Code Here

getServletInfo

public String getServletInfo()
Returns a string describing the servlet.
Specified by:
getServletInfo in interface Servlet

getServletName

public String getServletName()
Returns the servlet name for this configuration. For example, 'myservlet' in the following configuration:

 <servlet servlet-name='myservlet'
          servlet-class='test.MyServlet'/>
 
Specified by:
getServletName in interface ServletConfig

init

public void init()
            throws ServletException
Initialize the servlet. Servlets should override this method if they need any initialization like opening pooled database connections.

init

public void init(ServletConfig config)
            throws ServletException
Initialize the servlet. Most servlets should override the zero parameter init() instead.
Specified by:
init in interface Servlet
Parameters:
config - the servlet's configuration

log

public void log(String message)
Logs an error message in the application's log.
Usages and Demos :

View More Examples of log(String message)
   1: 
   2: import javax.servlet.GenericServlet;
   3: 
   4:         ...
   5: 
   6:         protected GenericServlet servlet = null;
   7: 
   8:         ...
   9:                 throw new java.lang.UnsupportedOperationException( 
  10:                         "ServletLogBridge can be created only with ServletLogBridge( GenericServlet servlet ) constructor!" );
  11:         }
  12:         ...
  13:         public void log( String message ) {
  14:                 servlet.log( buildMessage( message ) );

View Full Code Here

log

public void log(String message,
                Throwable cause)
Logs an error message and an exception trace in the application's log.