1. GenericServlet
    1. a generic, protocol-independent servlet.
  2. HttpServlet
    1. An HTTP servlet for use on the Web
    2. A typical sequence of events
      1. 1. 终端发送请求.
      2. 2. 请求被Web Server接收并交由Servelt Container处理.
      3. 3. Servelt Container调用相关的Servlet处理.
      4. 4. Serlvet使用Request对象确认终端 处理业务逻辑 生成数据使用Respose对象发送到终端.
      5. 5. 一旦Servlet完成 Servlet Container确保Response被刷新(flushed) 然后将控制权交由Web Server.
    3. Request Handling Methods
      1. doGet
      2. doPost
      3. doPut HTTP/1.1
      4. doDelete HTTP/1.1
      5. doHead It returns only the headers produced by the doGet method
      6. doOptions
      7. doTrace
    4. For a servlet not hosted in a distributed environment (the default), the servlet container must use only one instance per servlet declaration.
    5. Life Cycle
      1. Loading and Instantiation
      2. Initialization
      3. Request Handling
        1. Multithreading Issues
          1. SingleThreadModel
          2. synchronize the service method is evil
          3. the request and response objects are not thread safe
        2. Exceptions During Request Handling
        3. Thread Safety
          1. Be aware that the request and response objects are not thread safe.
      4. End of Service
  3. Request
    1. HTTP Protocol Parameters
    2. Attributes
    3. Headers
    4. Request Path Elements
      1. Context Path
      2. Servlet Path
      3. PathInfo
      4. requestURI = contextPath + servletPath + pathInfo
    5. Cookies
    6. SSL Attributes
    7. Internationalization
    8. Request data encoding
      1. parse POST data must be “ISO-8859-1” if none has been specified.
    9. Lifetime
      1. Each request object is valid only within the scope of a servlet’s service method.
      2. Maintaining references to request objects outside the scope is not recommended .
  4. Servlet Context
    1. The Container Provider is responsible for providing an implementation of the ServletContext interface in the servlet container.
    2. Scope
      1. There is one instance object of the ServletContext interface associated with each Web application deployed into a container.
      2. In cases where the container is distributed over many virtual machines, a Web application will have an instance of the ServletContext for each JVM.
    3. Initialization Parameters
    4. Context Attributes
      1. Context attributes are local to the JVM in which they were created.
      2. ServletContext attributes can not share in a distributed container.
    5. Resources
    6. Multiple Hosts and Servlet Contexts
      1. Servlet contexts can not be shared across virtual hosts.
  5. Response
    1. Buffering
    2. Headers
    3. Internationalization
    4. Closure of Response Object
      1. When a response is closed, the container must immediately flush all remaining content in the response buffer to the client.
    5. Lifetime
  6. Filtering
    1. javax.servlet.Filter
    2. Filters and the RequestDispatcher
  7. Sessions
    1. The Hypertext Transfer Protocol (HTTP) is by design a stateless protocol.
    2. Session Tracking Mechanisms
      1. Cookies
      2. SSL(Secure Sockets Layer) Sessions
      3. URL Rewriting: http://localhost/app/index.html;jsessionid=1234 (must be jsessionid)
    3. Scope
      1. session的作用范围仅限于当前应用程序下, 不同的应用之间是不能够互相访问
    4. Session Timeouts
    5. Last Accessed Times
    6. Important Session Semantics
      1. Threading Issues
      2. Distributed Environments
      3. Client Semantics
  8. Dispatching Requests
    1. The Include Method
      1. Any attempt to set the headers with the response object must be ignored.
    2. The Forward Method
      1. The method may be called by the calling servlet only when no output has been committed
    3. Error Handling