Skip to main content

CGI working; JSP vs ASP; AJAX

Short answer

CGI works by the web server spawning a new process for each request, passing data via environment variables and standard input, and returning the script's stdout output to the browser. Compared to ASP which is Windows-bound, JSP is platform-independent, compiled Java. AJAX is preferred because it updates page parts asynchronously without full reloads, improving responsiveness and user experience.

How does CGI work? Compare JSP and ASP. What do you prefer to use AJAX?

How CGI works

The Common Gateway Interface (CGI) is a standard method by which a web server runs an external program and sends its output to the browser. It is used to create dynamic pages.

Steps:

  1. The browser requests a URL that points to a CGI program, or submits a form (GET or POST).
  2. The web server sees that the file is a CGI script (for example in /cgi-bin/) and starts it as a new process.
  3. The server passes request information to the script through environment variables (QUERY_STRING, REQUEST_METHOD, CONTENT_LENGTH) and standard input (for POST data).
  4. The script reads the data, does the work (database query, calculation) and writes the result to standard output, starting with a header such as Content-type: text/html, a blank line, then the HTML.
  5. The server returns this output to the browser. The process ends.
 Browser --request--> [Web Server] --env/stdin--> [CGI]
 Browser <--HTML----- [Web Server] <--stdout----- [CGI]
                           (script in Perl, C, Python)

Its weakness is that every request starts a new process, which is slow for busy sites. FastCGI and server modules solve this.

JSP versus ASP

PointJSP (JavaServer Pages)ASP (Active Server Pages)
DeveloperSun/Oracle (Java EE)Microsoft
LanguageJavaVBScript or JScript (ASP.NET: C#, VB.NET)
PlatformPlatform independent (any OS with a servlet container such as Tomcat)Mainly Windows with IIS
ExecutionCompiled to servlets, then run on the JVMClassic ASP is interpreted; ASP.NET is compiled
PerformanceFast after first compile; good scalabilityClassic ASP slower; ASP.NET is fast
ReuseJavaBeans, custom tags, servletsCOM components, .NET classes
CostFree servers available (Tomcat)Needs Windows server licence
SecurityJava security modelWindows/IIS security

Why prefer AJAX

AJAX (Asynchronous JavaScript and XML) updates part of a page without reloading the whole page. It is preferred because:

  • Pages are faster and more responsive, since only small data is exchanged.
  • It saves bandwidth and server load.
  • The user can keep working while the request runs in the background.
  • It gives a desktop-like experience (live search suggestions, form validation, chat, maps).
  • It works in standard browsers without plug-ins.

Its cost is more JavaScript complexity, harder back-button and bookmarking behaviour, and a need for care with search-engine indexing.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Internet and Intranet chapter 6 questions →