Jakarta Servlet: Difference between revisions

Content deleted Content added
Compared with other web application models: intentional section blank; only a single reference and this seems to be comparing a server-side web API vs. network protocols (i.e., apples vs. oranges)
Tag: section blanking
Line 50:
| Servlet 1.0 || December 1996|| {{n/a}} || || Part of June 1997 Java Servlet Development Kit (JSDK) 1.0<ref name="Hunter200003"/>
|}
 
== Compared with other web application models ==
{{one source|section|date=December 2013}}
The advantages of using servlets are their fast performance and ease of use combined with more power over traditional [[Common Gateway Interface|CGI]] (Common Gateway Interface). Traditional CGI scripts written in Java have a number of performance disadvantages:
* When an HTTP request is made, a new process is created each time the CGI script is called. The overhead associated with process creation can dominate the workload especially when the script does relatively fast operations. Thus, process creation will take more time for CGI script execution. In contrast, for servlets, each request is handled by a separate Java thread ''within'' the web server process, thereby avoiding the overhead associated with forking processes within the [[HTTP daemon]].
* Simultaneous CGI requests will load the CGI script to be copied into memory once per request. With servlets, there is only one copy that persists across requests and is shared between threads.
* Only a single instance answers all requests concurrently. This reduces memory usage and eases the management of persistent data.
* A servlet can be run by a servlet container in a restrictive environment, called a [[sandbox (computer security)|sandbox]]. This is similar to an [[applet]] that runs in the sandbox of the web browser. This enables restricted use of potentially harmful servlets.<ref name=r1/> CGI programs can of course also sandbox themselves, since they are simply OS processes.
 
Technologies like [[FastCGI]] and its derivatives (including [[Simple Common Gateway Interface|SCGI]], [[Apache JServ Protocol|AJP]]) do not exhibit the performance disadvantages of CGI, incurred by the constant process spawning. They are, however, roughly as simple as CGI. They are therefore also in contrast with servlets which are substantially more complex.
 
== Life cycle of a servlet ==