javax.servlet.Servlet翻译

来源:互联网 发布:c语言将数存储在数组中 编辑:程序博客网 时间:2024/04/30 01:56
 Overview Package  Class Tree Deprecated Index Help JavaTM 2 Platform
Ent. Ed. v1.4
 PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD

javax.servlet
Interface Servlet

All Known Subinterfaces:
HttpJspPage, JspPage
All Known Implementing Classes:
GenericServlet

public interface Servlet

Defines methods that all servlets must implement. 定义所有Servlets必须实现的方法。

A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol. servlet是运行在web服务器上的Java小程序,Servlets通常通过HTTP(超文本传输协议)接收并响应web客户端的请求,

To implement this interface, you can write a generic servlet that extends javax.servlet.GenericServlet or an HTTP servlet that extends javax.servlet.http.HttpServlet. 为了实现这个接口,你可以继承javax.servlet.GenericServlet类或者继承javax.servlet.http.HttpServlet类。

This interface defines methods to initialize a servlet, to service requests, and to remove a servlet from the server. These are known as life-cycle methods and are called in the following sequence: 该接口定义了方法来初始化servlet,处理请求,和删除服务器上的servlet。 这些生命周期的方法按以下顺序调用。

  1. The servlet is constructed, then initialized with the init method. 构造servlet,然后init方法初始化。
  2. Any calls from clients to the service method are handled. 处理客户端对service方法的任何调用。
  3. The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized. servlet从服务中取出,然后destory方法清除,接着垃圾收集和终止。

In addition to the life-cycle methods, this interface provides the getServletConfig method, which the servlet can use to get any startup information, and the getServletInfo method, which allows the servlet to return basic information about itself, such as author, version, and copyright. 除了这些生命周期方法之外,该接口还提供了getServletConfig方法,servlet用来获取启动信息, getServletInfo方法,允许servlet返回它自身的基本信息,比如作者、版本和版权。

Version:
$Version$
Author:
Various
See Also:
GenericServlet, HttpServlet

Method Summary voiddestroy()
          Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. 由servlet容器调用,表示servlet正被服务清除。
 ServletConfiggetServletConfig()
          Returns a
ServletConfig object, which contains initialization and startup parameters for this servlet.返回ServletConfig对象,包含该servlet的启动参数。  StringgetServletInfo()
          Returns information about the servlet, such as author, version, and copyright. 返回servlet的信息,例如作者、版本和版权。
 voidinit(ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.由servlet容器调用,表示servlet正被放入服务。
 voidservice(ServletRequest req, ServletResponse res)
          Called by the servlet container to allow the servlet to respond to a request.由servlet容器调用,允许servlet响应请求。
 

Method Detail

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. 由servlet容器调用,表示servlet正被放入服务。

The servlet container calls the init method exactly once after instantiating the servlet. The init method must complete successfully before the servlet can receive any requests. 在初始化servlet之后,实际上servlet容器仅调用init方法一次。init方法在servlet能接收请求之前必须成功执行。

The servlet container cannot place the servlet into service if the init method 如果init方法有以下情况出现,servlet容器将不能把servlet放入服务。

  1. Throws a ServletException 抛出ServletException
  2. Does not return within a time period defined by the Web server 在Web服务器定义的时间周期内不能返回

Parameters:
config - a ServletConfig object containing the servlet's configuration and initialization parameters ServletConfig对象,包含servlet配置和初始化参数
Throws:
ServletException - if an exception has occurred that interferes with the servlet's normal operation 如果servlet的正常操作中发生异常时抛出
See Also:
UnavailableException, getServletConfig()

getServletConfig

public ServletConfig getServletConfig()
Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. The ServletConfig object returned is the one passed to the init method. 返回ServletConfig对象,包含该servlet的启动参数。返回的ServletConfig对象传递给init方法。

Implementations of this interface are responsible for storing the ServletConfig object so that this method can return it. The GenericServlet class, which implements this interface, already does this. 实现了该接口可以对ServletConfig进行保存,因为该方法能够返回它。GenericServlet类实现了该接口,已经可以完成此任务。

Returns:
the ServletConfig object that initializes this servlet 初始化servlet的ServletConfig对象
See Also:
init(javax.servlet.ServletConfig)

service

public void service(ServletRequest req,                    ServletResponse res)             throws ServletException,                    IOException
Called by the servlet container to allow the servlet to respond to a request. 由servlet容器调用,允许servlet响应请求。

This method is only called after the servlet's init() method has completed successfully. 在servlet的init方法成功执行之后该方法仅被调用一次。

The status code of the response always should be set for a servlet that throws or sends an error. 响应状态码应该始终设置给servlet,用于抛出或发送错误。

Servlets typically run inside multithreaded servlet containers that can handle multiple requests concurrently. Developers must be aware to synchronize access to any shared resources such as files, network connections, and as well as the servlet's class and instance variables. More information on multithreaded programming in Java is available in the Java tutorial on multi-threaded programming. servlet通常运行在多线程的servlet容器内部,可以并发处理多请求。开发人员 必须意识到对于任何共享资源,例如文件、网络连接,包括servlet的类和实例变量,进行同步访问。

Parameters:
req - the ServletRequest object that contains the client's request 包含客户端请求的ServletRequest对象
res - the ServletResponse object that contains the servlet's response 包含servlet响应的ServletResponse对象
Throws:
ServletException - if an exception occurs that interferes with the servlet's normal operation 如果妨碍servlet正常工作的异常发生时抛出
IOException - if an input or output exception occurs 如果输入输出异常发生时抛出

getServletInfo

public String getServletInfo()
Returns information about the servlet, such as author, version, and copyright. 返回servlet的信息,例如作者、版本和版权。

The string that this method returns should be plain text and not markup of any kind (such as HTML, XML, etc.). 该方法返回的字符串应当是纯文本,不含HTML、XML等标记符。

Returns:
a String containing servlet information 包含servlet信息的字符串

destroy

public void destroy()
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet. 由servlet容器调用,表示servlet正被服务清除。该方法只在servlet的service方法退出或者超时被所有线程调用一次。 servlet容器调用该方法后,servlet不会再次调用service方法。

This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory. 该方法使得servlet有机会清除持有的所有资源(例如内存、文件处理、线程),确保任何持久化状态与内存中servlet的当前状态一致。


Overview Package  Class Tree Deprecated Index Help JavaTM 2 Platform
Ent. Ed. v1.4
 PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
Submit a bug or feature

Copyright 2003 Sun Microsystems, Inc. All rights reserved.

原创粉丝点击