javax.servlet.GenericServlet翻译

 
JavaTM 2 Platform
Ent. Ed. v1.4

javax.servlet
Class GenericServlet

java.lang.Object
  extended byjavax.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
 voiddestroy()
          Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. 由servlet容器调用,表示servlet正被清除出服务。
 StringgetInitParameter(String name)
          Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. 返回命名的初始化参数的对应String值,如果参数不存在返回null。
 EnumerationgetInitParameterNames()
          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。
 ServletConfiggetServletConfig()
          Returns this servlet's
ServletConfig object. 返回servlet的ServletConfig对象。
 ServletContextgetServletContext()
          Returns a reference to the
ServletContext in which this servlet is running. 返回正在运行的servlet的ServletContext的引用。
 StringgetServletInfo()
          Returns information about the servlet, such as author, version, and copyright. 返回servlet的信息,例如作者、版本和版权。
 StringgetServletName()
          Returns the name of this servlet instance. 返回servlet实例的名称。
 voidinit()
          A convenience method which can be overridden so that there's no need to call super.init(config). 能被重写的简便方法,以至于不需调用super.init(config)。
 voidinit(ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service. 由servlet容器调用,表示servlet正被放入服务。
 voidlog(String msg)
          Writes the specified message to a servlet log file, prepended by the servlet's name. 将详细信息写入servlet日志文件,含servlet名称。
 voidlog(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  voidservice(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()。

Specified by:
destroy in interface Servlet

getInitParameter

public String getInitParameter(String name)
Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. See ServletConfig.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 interface ServletConfig
Parameters:
name - a String 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 of String objects, or an empty Enumeration if the servlet has no initialization parameters. See ServletConfig.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 interface ServletConfig
Returns:
Enumeration an enumeration of String objects containing the names of the servlet's initialization parameters String对象的枚举,包含初始化变量的名称

getServletConfig

public ServletConfig getServletConfig()
Returns this servlet's ServletConfig object. 返回servlet的ServletConfig对象。

Specified by:
getServletConfig in interface Servlet
Returns:
ServletConfig the ServletConfig object that initialized this servlet 初始化servlet的ServletConfig对象
See Also:
Servlet.init(javax.servlet.ServletConfig)

getServletContext

public ServletContext getServletContext()
Returns a reference to the ServletContext in which this servlet is running. See ServletConfig.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 interface ServletConfig
Returns:
ServletContext the ServletContext object passed to this servlet by the init method 通过init方法传递给servlet的ServletContext对象
See Also:
ServletContext

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 interface Servlet
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, call super.init(config). 该实现保存了从servlet容器接收到的ServletConfig对象留作后用。重写该方法时,应调用super.init(config)。

Specified by:
init in interface Servlet
Parameters:
config - the ServletConfig 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 by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig(). 代之重写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 - a String 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. See ServletContext.log(String, Throwable) . 将说明信息和给出的Throwable异常堆栈跟踪写入servlet日志文件,含servlet名称。参见ServletContext.log(String, Throwable)。

Parameters:
message - a String that describes the error or exception 描述错误或异常的String
t - the java.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必须重载它。

Specified by:
service in interface Servlet
Parameters:
req - the ServletRequest object that contains the client's request 包含客户端请求的ServletRequest对象
res - the ServletResponse 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 interface ServletConfig
Returns:
the name of this servlet instance servlet实例名称

JavaTM 2 Platform
Ent. Ed. v1.4

Submit a bug or feature

Copyright 2003 Sun Microsystems, Inc. All rights reserved.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值