Servlet规范中的 interface 和 class

摘自javax.servlet.*类的javadoc

interface javax.servlet.Servlet
Defines methods that all servlets must implement.
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)

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.

This interface defines methods to initialize a servlet, to service requests, and to remove a servlet from the server.(life-cycle methods)

  1. The servlet is constructed, then initialized with the init method.
  2. Any calls from clients to the service method are handled.
  3. The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized.
servlet在服务器中的生命周期:1.加载 ->2.初始化 - > 3.调用 - 4.销毁
 
abstract  javax.servlet.http.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:
  1. doGet, if the servlet supports HTTP GET requests
  2. doPost, for HTTP POST requests
  3. doPut, for HTTP PUT requests
  4. doDelete, for HTTP DELETE requests
  5. init and destroy, to manage resources that are held for the life of the servlet
  6. getServletInfo, which the servlet uses to provide information about itself
  • service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods listed above).

Servlets typically run on multithreaded servers, so be aware that a servlet must handle concurrent requests and be careful to synchronize access to shared resources. 

 
interface javax.servlet.http.HttpServletRequest
The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).
 
 
interface javax.servlet.http.HttpServletResponse
The servlet container creates an HttpServletResponse object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).
 
javax.servlet.http.Cookie
     Creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management. 
 
 
javax.servlet.http.HttpSession
     Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. 
     The servlet container uses this interface to create a session between an HTTP client and an HTTP server. The session persists for a specified time period, across more than one connection or page request from the user. A session usually corresponds to one user, who may visit a site many times. The server can maintain a session in many ways such as using cookies or rewriting URLs. 

转载于:https://www.cnblogs.com/windlaughing/archive/2013/03/27/2983967.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值