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的格式也自动被解析。