- 2074 Magh · 10 marks
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:
- The browser requests a URL that points to a CGI program, or submits a form (GET or POST).
- The web server sees that the file is a CGI script (for example in
/cgi-bin/) and starts it as a new process. - The server passes request information to the script through environment variables (QUERY_STRING, REQUEST_METHOD, CONTENT_LENGTH) and standard input (for POST data).
- 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. - 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
| Point | JSP (JavaServer Pages) | ASP (Active Server Pages) |
|---|---|---|
| Developer | Sun/Oracle (Java EE) | Microsoft |
| Language | Java | VBScript or JScript (ASP.NET: C#, VB.NET) |
| Platform | Platform independent (any OS with a servlet container such as Tomcat) | Mainly Windows with IIS |
| Execution | Compiled to servlets, then run on the JVM | Classic ASP is interpreted; ASP.NET is compiled |
| Performance | Fast after first compile; good scalability | Classic ASP slower; ASP.NET is fast |
| Reuse | JavaBeans, custom tags, servlets | COM components, .NET classes |
| Cost | Free servers available (Tomcat) | Needs Windows server licence |
| Security | Java security model | Windows/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)
Related questions
- AJAX features; CGI, Perl, JavaScript helpers · Internet and Intranet, chapter 6
- ASP working, advantages and disadvantages · Sanitary Engineering, chapter 7 · asked 2×
- AJAX and how it works · Web Technology, chapter 6 · asked 3×
- Prefer O(n) or O(log n) algorithm · Data Structure and Algorithm, chapter 9
- When to prefer lag/lead or PID controllers · Digital Control System, chapter 4