---
title: "CGI working; JSP vs ASP; AJAX"
subject: "Internet and Intranet"
chapter: 6
key: "semester_8/internet_and_intranet:cgi-jsp-asp-ajax"
source: https://www.bctengineer.com/q/semester_8/internet_and_intranet/cgi-jsp-asp-ajax
site: BCT Engineering
---

# CGI working; JSP vs ASP; AJAX

Internet and Intranet · Chapter 6: Internet and Intranet Systems Development

- Asked in: 2074 Magh, 10 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/internet_and_intranet/cgi-jsp-asp-ajax
- Whole chapter: https://www.bctengineer.com/md/semester_8/internet_and_intranet/chapter-6

## Question

How does CGI work? Compare JSP and ASP. What do you prefer to use 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.

## Answer

#### 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.

```text
 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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does the web server do when it receives a request for a CGI script?
   A. It starts the script as a new process and passes request data via environment variables and standard input
   B. It keeps the script running permanently
   C. It sends the script's source code to the browser
   D. It forwards the request to the browser's JavaScript engine
   Answer: A. Each request starts a new process; data come through environment variables (QUERY_STRING etc.) and stdin for POST. (Key point: CGI process model)

2. How must a CGI script start its output?
   A. With the database query
   B. With a header such as Content-type: text/html, a blank line, then the HTML
   C. With the HTML body immediately
   D. With an environment variable
   Answer: B. The script writes to standard output beginning with a header and a blank line before the content. (Key point: CGI output format)

3. What is the main weakness of CGI?
   A. It cannot use databases
   B. Every request starts a new process, which is slow for busy sites
   C. It works only on Windows
   D. It cannot create dynamic pages
   Answer: B. Process creation for each request is costly; FastCGI and server modules avoid it. (Key point: CGI weakness)

4. Which is a correct difference between JSP and ASP?
   A. JSP is platform independent using Java; ASP runs mainly on Windows with IIS
   B. JSP is Microsoft's and ASP is Sun's
   C. JSP is interpreted only, ASP is Java
   D. Both require Windows
   Answer: A. JSP is Java-based and runs on any OS with a servlet container such as Tomcat, while ASP is Microsoft's, mainly on IIS. (Key point: JSP vs ASP platform)

5. Why is AJAX preferred for interactive pages?
   A. It reloads the whole page faster
   B. It updates part of a page without reload, saving bandwidth and letting the user keep working
   C. It removes the need for a server
   D. It needs a browser plug-in
   Answer: B. Only small data are exchanged asynchronously and only part of the page changes. (Key point: Why prefer AJAX)

## Related in Internet and Intranet

- [AJAX features; CGI, Perl, JavaScript helpers](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Aajax-features-cgi-perl-js) — Internet and Intranet, chapter 6

## Related in other subjects

- [ASP working, advantages and disadvantages](https://www.bctengineer.com/question.md?key=semester_6%2Fsanitary_engineering%3Aasp-flow-diagram-advantages) — Sanitary Engineering, chapter 7, asked 2×
- [AJAX and how it works](https://www.bctengineer.com/question.md?key=semester_7%2Fweb_technology%3Aajax-request-response) — Web Technology, chapter 6, asked 3×
- [Prefer O(n) or O(log n) algorithm](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aprefer-on-or-ologn) — Data Structure and Algorithm, chapter 9
- [When to prefer lag/lead or PID controllers](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Alag-lead-vs-pid) — Digital Control System, chapter 4
