Movatterモバイル変換


[0]ホーム

URL:


         


Class GenericServlet

java.lang.Object  |  +--javax.servlet.GenericServlet
All Implemented Interfaces:
java.io.Serializable,Servlet,ServletConfig
Direct Known Subclasses:
HttpServlet

public abstract classGenericServlet
extends java.lang.Object
implementsServlet,ServletConfig, java.io.Serializable

Defines a generic, protocol-independent servlet. To write an HTTP servlet for use on the Web, extendHttpServlet instead.

GenericServlet implements theServlet andServletConfig interfaces.GenericServlet may be directly extended by a servlet, although it's more common to extend a protocol-specific subclass such asHttpServlet.

GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methodsinit anddestroy and of the methods in theServletConfig interface.GenericServlet also implements thelog method, declared in theServletContext interface.

To write a generic servlet, you need only override the abstractservice method.

See Also:
Serialized Form

GenericServlet()
          Does nothing.
 
destroy()
          Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
getInitParameter(java.lang.String name)
          Returns aString containing the value of the named initialization parameter, ornull if the parameter does not exist.
getInitParameterNames()
          Returns the names of the servlet's initialization parameters as anEnumeration ofString objects, or an emptyEnumeration if the servlet has no initialization parameters.
getServletConfig()
          Returns this servlet'sServletConfig object.
getServletContext()
          Returns a reference to theServletContext in which this servlet is running.
getServletInfo()
          Returns information about the servlet, such as author, version, and copyright.
getServletName()
          Returns the name of this servlet instance.
init()
          A convenience method which can be overridden so that there's no need to callsuper.init(config).
init(ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
log(java.lang.String msg)
          Writes the specified message to a servlet log file, prepended by the servlet's name.
log(java.lang.String message, java.lang.Throwable t)
          Writes an explanatory message and a stack trace for a givenThrowable exception to the servlet log file, prepended by the servlet's name.
service(ServletRequest req,ServletResponse res)
          Called by the servlet container to allow the servlet to respond to a request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

GenericServlet

publicGenericServlet()
Does nothing. All of the servlet initialization is done by one of theinit methods.

destroy

public voiddestroy()
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. SeeServlet.destroy().
Specified by:
destroy in interfaceServlet

getInitParameter

public java.lang.StringgetInitParameter(java.lang.String name)
Returns aString containing the value of the named initialization parameter, ornull if the parameter does not exist. SeeServletConfig.getInitParameter(java.lang.String).

This method is supplied for convenience. It gets the value of the named parameter from the servlet'sServletConfig object.

Specified by:
getInitParameter in interfaceServletConfig
Parameters:
name - aString specifying the name of the initialization parameter
Returns:
String aString containing the valueof the initalization parameter

getInitParameterNames

public java.util.EnumerationgetInitParameterNames()
Returns the names of the servlet's initialization parameters as anEnumeration ofString objects, or an emptyEnumeration if the servlet has no initialization parameters. SeeServletConfig.getInitParameterNames().

This method is supplied for convenience. It gets the parameter names from the servlet'sServletConfig object.

Specified by:
getInitParameterNames in interfaceServletConfig
Returns:
Enumeration an enumeration ofStringobjects containing the names of the servlet's initialization parameters

getServletConfig

publicServletConfiggetServletConfig()
Returns this servlet'sServletConfig object.
Specified by:
getServletConfig in interfaceServlet
Returns:
ServletConfig theServletConfig objectthat initialized this servlet

getServletContext

publicServletContextgetServletContext()
Returns a reference to theServletContext in which this servlet is running. SeeServletConfig.getServletContext().

This method is supplied for convenience. It gets the context from the servlet'sServletConfig object.

Specified by:
getServletContext in interfaceServletConfig
Returns:
ServletContext theServletContext objectpassed to this servlet by theinitmethod

getServletInfo

public java.lang.StringgetServletInfo()
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. SeeServlet.getServletInfo().
Specified by:
getServletInfo in interfaceServlet
Returns:
String information about this servlet, by default an empty string

init

public voidinit(ServletConfig config)          throwsServletException
Called by the servlet container to indicate to a servlet that the servlet is being placed into service. SeeServlet.init(javax.servlet.ServletConfig).

This implementation stores theServletConfig object it receives from the servlet container for later use. When overriding this form of the method, callsuper.init(config).

Specified by:
init in interfaceServlet
Parameters:
config - theServletConfig objectthat contains configutationinformation for this servlet
Throws:
ServletException - if an exception occurs thatinterrupts the servlet's normaloperation
See Also:
UnavailableException

init

public voidinit()          throwsServletException
A convenience method which can be overridden so that there's no need to callsuper.init(config).

Instead of overridinginit(ServletConfig), simply override this method and it will be called byGenericServlet.init(ServletConfig config). TheServletConfig object can still be retrieved viagetServletConfig().

Throws:
ServletException - if an exception occurs thatinterrupts the servlet'snormal operation

log

public voidlog(java.lang.String msg)
Writes the specified message to a servlet log file, prepended by the servlet's name. SeeServletContext.log(String).
Parameters:
msg - aString specifyingthe message to be written to the log file

log

public voidlog(java.lang.String message,                java.lang.Throwable t)
Writes an explanatory message and a stack trace for a givenThrowable exception to the servlet log file, prepended by the servlet's name. SeeServletContext.log(String, Throwable).
Parameters:
message - aString that describesthe error or exception
t - thejava.lang.Throwable error or exception

service

public abstract voidservice(ServletRequest req,ServletResponse res)                      throwsServletException,                             java.io.IOException
Called by the servlet container to allow the servlet to respond to a request. SeeServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse).

This method is declared abstract so subclasses, such asHttpServlet, must override it.

Specified by:
service in interfaceServlet
Parameters:
req - theServletRequest objectthat contains the client's request
res - theServletResponse objectthat will contain the servlet's response
Throws:
ServletException - if an exception occurs thatinterferes with the servlet'snormal operation occurred
java.io.IOException - if an input or outputexception occurs

getServletName

public java.lang.StringgetServletName()
Returns the name of this servlet instance. SeeServletConfig.getServletName().
Specified by:
getServletName in interfaceServletConfig
Returns:
the name of this servlet instance

         


[8]ページ先頭

©2009-2025 Movatter.jp