1.Servlet接口java
destroy | Called by the servlet container to indicate(代表,指示) to a servlet that the servlet is being taken out of service. |
getServletConfig | Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. |
getServletInfo | Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. |
init(ServletConfig)web init()服務器 |
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.post |
service(ServletRequest req,this ServletResponse resp)spa |
Called by the servlet container to allow the servlet to respond to a request. |
建立時機: 在建立完servlet對象以後,在調用init方法以前建立。對象
獲得對象: 直接從有參數的init方法中獲得!!!blog
servlet初始化流程:服務器收到http請求,接口
- Servlet容器建立一個HttpRequest對象,將Web Client請求的信息封裝到這個對象中。
- Servlet容器建立一個HttpResponse對象
建立servlet對象(若是是第一次請求或更新以後)ci
初始化servlet對象
調用service方法
getInitParameter | Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist |
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 |
getServletContext | Returns a reference to the ServletContext in which the caller is executing |
getServletName | Returns the name of this servlet instance |
2.GenericServlet抽象類
http://even2012.iteye.com/blog/1838063
ServletContext 對象包含在 ServletConfig 對象中,ServletConfig 對象在初始化 servlet 時由 Web 服務器提供給 servlet。
3.HttpServlet 抽象類
HttpServletRequest,HttpServletResponse
HTTP請求剛剛進來的時候實際上只是一個HTTP請求報文,容器會自動將這個HTTP請求報文包裝成一個HttpServletRequest對象,而且自動調用HttpServlet的service()方法來解析這個HTTP請求,service()方法會解析HTTP請求行,而HTTP請求行由method,uri,HTTP version三個組成,method就是get或者post,service()方法根據method來決定是執行doGet仍是doPost,這一切都是服務器Tomcat/weblogic/websphere/jboss(容器)自動完成的,HTTP的格式也自動被解析。