| JavaTM 2 Platform Ent. Ed. v1.4 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <script type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </script> All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.servlet
Class GenericServlet
java.lang.Object javax.servlet.GenericServlet
-
All Implemented Interfaces:
- Serializable , Servlet , ServletConfig
-
Direct Known Subclasses:
- HttpServlet
-
public abstract class GenericServlet
extends
Object
implements
Servlet
,
ServletConfig
,
Serializable
Defines a generic, protocol-independent servlet. To write an HTTP servlet for use on the Web, extend HttpServlet
instead. 定义了一个一般的,与协议无关的servlet。为了写一个HTTP servlet在Web上使用,应当继承HttpServlet。
GenericServlet
implements the Servlet
and ServletConfig
interfaces. GenericServlet
may be directly extended by a servlet, although it's more common to extend a protocol-specific subclass such as HttpServlet
. GenericServlet实现了Servlet和ServletConfig接口。GenericServlet可以直接被servlet继承,尽管继承一个指定协议的子类比如HttpServlet更常用。
GenericServlet
makes writing servlets easier. It provides simple versions of the lifecycle methods init
and destroy
and of the methods in the ServletConfig
interface. GenericServlet
also implements the log
method, declared in the ServletContext
interface. GenericServlet使得写servlet更容易。它提供了生命周期方法init、destroy和ServletConfig接口方法的简单版本。 GenericServlet也实现了在ServletContext接口中声明的log方法。
To write a generic servlet, you need only override the abstract service
method. 写一个generic servlet,你只需要重写抽象方法service。
-
Version:
- $Version$ Author:
- Various See Also:
- Serialized Form
Constructor Summary | |
GenericServlet() Does nothing. 不做任何事。 |
Method Summary | |
void | destroy() Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. 由servlet容器调用,表示servlet正被清除出服务。 |
String | getInitParameter(String name) Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. 返回命名的初始化参数的对应String值,如果参数不存在返回null。 |
Enumeration | getInitParameterNames() Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters. 返回以String对象的Enumeration形式的servlet初始化参数名称,如果servlet不含初始化参数,返回一个空Enumeration。 |
ServletConfig | getServletConfig() Returns this servlet's ServletConfig object. 返回servlet的ServletConfig对象。 |
ServletContext | getServletContext() Returns a reference to the ServletContext in which this servlet is running. 返回正在运行的servlet的ServletContext的引用。 |
String | getServletInfo() Returns information about the servlet, such as author, version, and copyright. 返回servlet的信息,例如作者、版本和版权。 |
String | getServletName() Returns the name of this servlet instance. 返回servlet实例的名称。 |
void | init() A convenience method which can be overridden so that there's no need to call super.init(config) . 能被重写的简便方法,以至于不需调用super.init(config)。 |
void | init(ServletConfig config) Called by the servlet container to indicate to a servlet that the servlet is being placed into service. 由servlet容器调用,表示servlet正被放入服务。 |
void | log(String msg) Writes the specified message to a servlet log file, prepended by the servlet's name. 将详细信息写入servlet日志文件,含servlet名称。 |
void | log(String message, Throwable t) Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file, prepended by the servlet's name. 将说明信息和给出的Throwable异常堆栈跟踪写入servlet日志文件,含servlet名称。 |
abstract void | service(ServletRequest req, ServletResponse res) Called by the servlet container to allow the servlet to respond to a request. 由servlet容器调用,允许servlet响应请求。 |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
GenericServlet
public GenericServlet()
-
Does nothing. All of the servlet initialization is done by one of the
init
methods. 不做任何事。所有servlet初始化都由某个init方法完成。
Method Detail |
destroy
public void destroy()
-
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. See
Servlet.destroy()
. 由servlet容器调用,表示servlet正被清除出服务。参见Servlet.destroy()。 -
getInitParameter
public String getInitParameter(String name)
-
Returns a
String
containing the value of the named initialization parameter, ornull
if the parameter does not exist. SeeServletConfig.getInitParameter(java.lang.String)
. 返回命名的初始化参数的对应String值,如果参数不存在返回null。参见ServletConfig.getInitParameter(java.lang.String)。This method is supplied for convenience. It gets the value of the named parameter from the servlet's
ServletConfig
object. 该方法为了简便起见提供,从servlet的ServletConfig对象中获得指定名称的参数值。 -
-
Specified by:
-
getInitParameter
in interfaceServletConfig
-
-
-
Parameters:
-
name
- aString
specifying the name of the initialization parameter String,指定初始化参数的名称
Returns:
-
String a
String
containing the value of the initalization parameter 包含初始化参数值的String
-
getInitParameterNames
public Enumeration getInitParameterNames()
-
Returns the names of the servlet's initialization parameters as an
Enumeration
ofString
objects, or an emptyEnumeration
if the servlet has no initialization parameters. SeeServletConfig.getInitParameterNames()
. 返回以String对象的Enumeration形式的servlet初始化参数名称,如果servlet不含初始化参数,返回一个空Enumeration。参见ServletConfig.getInitParameterNames()。This method is supplied for convenience. It gets the parameter names from the servlet's
ServletConfig
object. 该方法为了简便起见提供,从servlet的ServletConfig对象中获得参数名称。 -
-
Specified by:
-
getInitParameterNames
in interfaceServletConfig
-
-
-
Returns:
-
Enumeration an enumeration of
String
objects containing the names of the servlet's initialization parameters String对象的枚举,包含初始化变量的名称
-
Enumeration an enumeration of
getServletConfig
public ServletConfig getServletConfig()
-
Returns this servlet's
ServletConfig
object. 返回servlet的ServletConfig对象。 -
-
Specified by:
-
getServletConfig
in interfaceServlet
-
-
-
Returns:
-
ServletConfig the
ServletConfig
object that initialized this servlet 初始化servlet的ServletConfig对象
See Also:
-
Servlet.init(javax.servlet.ServletConfig)
-
ServletConfig the
getServletContext
public ServletContext getServletContext()
-
Returns a reference to the
ServletContext
in which this servlet is running. SeeServletConfig.getServletContext()
. 返回正在运行的servlet的ServletContext的引用。参见ServletConfig.getServletContext()。This method is supplied for convenience. It gets the context from the servlet's
ServletConfig
object. 该方法为了简便起见提供,从servlet的ServletConfig对象中获得上下文。 -
-
Specified by:
-
getServletContext
in interfaceServletConfig
-
-
-
Returns:
-
ServletContext the
ServletContext
object passed to this servlet by theinit
method 通过init方法传递给servlet的ServletContext对象
See Also:
-
ServletContext
-
ServletContext the
getServletInfo
public String getServletInfo()
-
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. See
Servlet.getServletInfo()
. 返回servlet的信息,例如作者、版本和版权。 默认返回空字符串。重写本方法,可以让它返回一个有意义的值。参见Servlet.getServletInfo()。 -
-
Specified by:
-
getServletInfo
in interfaceServlet
-
-
-
Returns:
- String information about this servlet, by default an empty string 关于servlet的信息,墨认为空字符串
init
public void init(ServletConfig config) throws ServletException
-
Called by the servlet container to indicate to a servlet that the servlet is being placed into service. See
Servlet.init(javax.servlet.ServletConfig)
. 由servlet容器调用,表示servlet正被放入服务。参见Servlet.init(javax.servlet.ServletConfig)。This implementation stores the
ServletConfig
object it receives from the servlet container for later use. When overriding this form of the method, callsuper.init(config)
. 该实现保存了从servlet容器接收到的ServletConfig对象留作后用。重写该方法时,应调用super.init(config)。 -
-
Parameters:
-
config
- theServletConfig
object that contains configutation information for this servlet ServletConfig对象,包含servlet的配置信息
Throws:
-
ServletException
- if an exception occurs that interrupts the servlet's normal operation 如果异常发生,阻止servlet的正常操作时抛出
See Also:
-
UnavailableException
-
init
public void init() throws ServletException
-
A convenience method which can be overridden so that there's no need to call
super.init(config)
. 能被重写的简便方法,以至于不需调用super.init(config)。Instead of overriding
init(ServletConfig)
, simply override this method and it will be called byGenericServlet.init(ServletConfig config)
. TheServletConfig
object can still be retrieved viagetServletConfig()
. 代之重写init(ServletConfig),可以简单重写本方法,它将会被GenericServlet.init(ServletConfig config)调用。 ServletConfig对象仍然可以通过getServletConfig()获得。 -
-
-
Throws:
-
ServletException
- if an exception occurs that interrupts the servlet's normal operation 如果异常发生,阻止servlet的正常操作时抛出
-
log
public void log(String msg)
-
Writes the specified message to a servlet log file, prepended by the servlet's name. See
ServletContext.log(String)
. 将详细信息写入servlet日志文件,含servlet名称。参见ServletContext.log(String)。 -
-
-
Parameters:
-
msg
- aString
specifying the message to be written to the log file String,指定写入日志文件的信息
-
log
public void log(String message, Throwable t)
-
Writes an explanatory message and a stack trace for a given
Throwable
exception to the servlet log file, prepended by the servlet's name. SeeServletContext.log(String, Throwable)
. 将说明信息和给出的Throwable异常堆栈跟踪写入servlet日志文件,含servlet名称。参见ServletContext.log(String, Throwable)。 -
-
-
Parameters:
-
message
- aString
that describes the error or exception 描述错误或异常的String -
t
- thejava.lang.Throwable
error or exception java.lang.Throwable错误或异常
-
service
public abstract void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
-
Called by the servlet container to allow the servlet to respond to a request. See
Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
. 由servlet容器调用,允许servlet响应请求。参见Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)。This method is declared abstract so subclasses, such as
HttpServlet
, must override it. 该方法被声明为抽象,所以子类,比如HttpServlet必须重载它。 -
-
Parameters:
-
req
- theServletRequest
object that contains the client's request 包含客户端请求的ServletRequest对象 -
res
- theServletResponse
object that will contain the servlet's response 包含客户端响应的ServletResponse对象
Throws:
-
ServletException
- if an exception occurs that interferes with the servlet's normal operation occurred 如果异常发生,阻止servlet的正常操作时抛出 -
IOException
- if an input or output exception occurs 如果输入输出异常发生时抛出
-
getServletName
public String getServletName()
-
Returns the name of this servlet instance. See
ServletConfig.getServletName()
. 返回servlet实例的名称。 参见ServletConfig.getServletName()。 -
-
Specified by:
-
getServletName
in interfaceServletConfig
-
-
-
Returns:
- the name of this servlet instance servlet实例名称
| JavaTM 2 Platform Ent. Ed. v1.4 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <script type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </script> All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2003 Sun Microsystems, Inc. All rights reserved.