Here is a simple Java program that receives a request from a browser and writes out the request. It listens on port 1234. By default Web browsers submit a request to port 80 and most Web servers are configered to listen on port 80.
Using Common Gateway Interface (CGI) to connect a program to a Web server
For CGIs, each request requires starting a new process (i.e. a new running program).
Except for the latest version of ASP (ASP.net), these technologies use high-level code that must be interpreted to produce dynamic HTML content.
Servlets are components written in Java that generate HTML content
JSPs work like templates but are efficiently translated into servlets and then compiled into Java byte code.