Servlet接口

Servlet

 void destroy()
          Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
 ServletConfig getServletConfig()
          Returns a ServletConfig object, which contains initialization and startup parameters for this servlet.
 java.lang.String getServletInfo()
          Returns information about the servlet, such as author, version, and copyright.
 void init(ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
 void service(ServletRequest req, ServletResponse res)
          Called by the servlet container to allow the servlet to respond to a request.

 

GenericServlet类

init()
          A convenience method which can be overridden so that there's no need to call super.init(config).

 

HttpServlet类

 

Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:

  • doGet, if the servlet supports HTTP GET requests
  • doPost, for HTTP POST requests
  • doPut, for HTTP PUT requests
  • doDelete, for HTTP DELETE requests
  • init and destroy, to manage resources that are held for the life of the servlet
  • getServletInfo, which the servlet uses to provide information about itself

 

 

 

ServletRequest接口的部分方法

方法名

描述

getAttribute

根据参数给定的属性名返回属性值。

getContentType

返回客户请求数据的MIME类型

getInputStream

返回以二进制数方式直接读取客户请求数据的输入流

getParameter

根据给定的参数名返回参数值

getRemoteAddr

返回远程客户主机的IP地址

getRemoteHost

返回远程客户主机名

getRemotePort

返回远程客房主机端口

setAttribute

ServletRequest中设置属性(包括属性名和属性值)

 

 

ServletResponse接口的部分方法

 

 

 

 

方法名

描述

getOutputStream

返回可以向客户端发送二进制数据的输出流对象ServletOutputStream

getWriter

返回可以向客户端发送字符数据的PrintWriter对象

getCharacterEncoding

返回Servlet发送的响应数据的字符编码

getContentType

返回Servlet发送的响应数据的MIME类型

setCharacterEncoding

设置Servlet发送的响应数据的字符编码

setContentType

设置Servlet发送的响应数据的MIME类型

你可能感兴趣的:(Web,servlet)