📜  Java Servlet 和 CGI 的区别

📅  最后修改于: 2021-09-15 01:34:11             🧑  作者: Mango

世界已进入移动优先时代,但即使在今天,也没有任何应用程序能像基于 Web 的应用程序那样有效。最重要的是,渐进式网络应用程序的流行,其执行的功能与移动应用程序相同。在本文中,我们将了解基于 Web 的应用程序(即 servlet 和 CGI)中的两种功能之间的区别。

Servlet: servlet 是一个Java类,用于扩展托管通过请求-响应模型访问的应用程序的服务器的功能。 Servlets 主要用于扩展 webs 服务器托管的应用程序,但是,它们也可以响应其他类型的请求。对于此类应用程序, Java Servlet 技术定义了特定于 HTTP 的 servlet 类。 Servlet 的所有程序都是用Java编写的,它们可以在Java虚拟机上运行。下图描述了如何在线程的帮助下处理来自客户端的请求:

通用网关接口 (CGI):通用网关接口 (CGI) 提供 WWW 服务器与外部数据库和信息源之间的中间件。万维网联盟 (W3C) 定义了通用网关接口 (CGI),还定义了程序如何与超文本传输协议 (HTTP) 服务器交互。 Web 服务器通常将表单信息传递给处理数据的小型应用程序,并可能会发回确认消息。这种在服务器和应用程序之间来回传递数据的过程或约定称为通用网关接口 (CGI)。下图描述了 Web 服务器如何充当 CGI 程序和客户端浏览器之间的中介。

下表解释了 servlet 和 CGI 之间的区别:

Basis Servlet CGI
Approach It is thread based i.e. for every new request new thread is created. It is process based i.e. for every new request new process is created.
Language Used The codes are written in JAVA programming language. The codes are written any programming language.
Object Oriented Since codes are written in Java, it is object oriented and the user will get the benefits of OOPs Since codes are written in any language, all the languages are not object oriented. So, the user will not get the benefits of OOPs
Portability It is portable. It is not portable.
Persistence It remains in the memory until it is not explicitly destroyed. It is removed from the memory after the completion of request.
Server Indepent It can use any of the web-server. It can use the web-server that supports it.
Data Sharing Data sharing is possible. Data sharing is not possible.
Link It links directly to the server. It does not links directly to the server.
HTTP server It can read and set HTTP servers. It can neither read nor set HTTP servers.
Cost Construction and destruction of new thread  is not costly.  Construction and destruction of new process is costly.