引用
The life cycle of a servlet is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps.
If an instance of the servlet does not exist, the Web container
Loads the servlet class.
Creates an instance of the servlet class.
Initializes the servlet instance by calling the init method. Initialization is covered in Initializing a Servlet.
Invokes the service method, passing a request and response object. Service methods are discussed in Writing Service Methods.
If the container needs to remove the servlet, it finalizes the servlet by calling the servlet's destroy method. Finalization is discussed in Finalizing a Servlet.
引用
Servlet被服务器实例化后,容器运行其init方法,请求到达时运行其service方法,service方法自动派遣运行与请求对应的doXXX方法(doGet,doPost)等,当服务器决定将实例销毁的时候调用其destroy方法。
与cgi的区别在于servlet处于服务器进程中,它通过多线程方式运行其service方法,一个实例可以服务于多个请求,并且其实例一般不会销毁,而CGI对每个请求都产生新的进程,服务完成后就销毁,所以效率上低于servlet
分享到:
相关推荐
servlet生命周期演示,便于理解servlet工作流程。
servlet生命周期详解
SERVLET生命周期与JSP生命周期比较
Servlet生命周期,web开发必须掌握到知识点,其中生命周期也是需要掌握的
Servlet生命周期与工作原理Servlet使用
servlet生命周期详细图解,矢量图。 详细的解释请参考本人博客:http://blog.csdn.net/dwyers/article/details/38435949
servlet生命周期和模版设计模式,包括代码以及相关文档
关于对Servlet声明周期的图例示意!
山寨qq项目1.登录界面教你学会制作qq登录及后台运行。
Servlet 生命周期
Java WEB 篇七 Servlet 生命周期
注:本示例中有5章图片,但因为上传比较麻烦,所以就放在附件中 博文链接:https://lvp.iteye.com/blog/234610
Servlet技术 两条主线 1、HTTP协议 2、Servlet生命周期
从三个阶段来描述servlet的生命周期:初始化阶段、运行阶段和销毁阶段。