
     Time zone web application

The code in this folder demonstrates a very simple "web application".

A "web application" is a program that you run from a web page. Web
pages are not programs. HTML is not a programming language, so you do
not write "web applications" in HTML. You write web applications in
some programming language, and then you need some way for your web
page (your HTML page) to trigger the execution of the code that you
wrote for your web application.

There are many ways for a web page to cause code to be executed. In
general, there are two fundamental ways for a web page to trigger the
execution of code that you wrote. First, your web page (your HTML page)
can tell the web browser to download from a web server some JavaScript
code (that you wrote) and then your web page (your HTML) can tell the
browser to execute that JavaScript code. Your code then runs in the
browser and causes whatever affects you want your web application to
accomplish.

The second way for your web page to cause code to be executed is for
your web page (your HTML page) to use HTTP to request a resource on
the web server that is actually a runnable program (instead of a static
resource like an HTML page or a png image). If your web page does an
HTTP GET, or HTTP POST, to a resource that is an executable program,
and if the web server is properly configured, then the web server can
execute (run) that resource, instead of sending it to your web page as
a static resource. If the web server runs the executable resource, then
the output from the execution is what the web server will send back to
your web page as the result of the HTTP GET (or POST) method. In this way
of running a web application, the code you write runs on the web server
and becomes a kind of extension to the web server itself.

The executable resource that you can request with a GET or POST can be any
program written in a language that the server is configured to allow and
that the computer running the web server knows how to execute. The most
common programming languages used these days for server side web applications
are PHP, Java (Java Server Pages), C# (Active Server Pages), Python (Django
and Flask) and JavaScript (Node).


Here is a diagram of a web browser communicating with a web server that is
executing a web application for the browser (in this case, a web application
written in Java). This picture does not describe how modern web applications
work. This picture is based on the older CGI (Common Gateway Interface) method
of running web applications. But this older, simpler, method explains the core
ideas behind running web applications on web servers.


 browser.exe                    server.exe            java.exe
 +---------+                   +---------+   pipe   +----------+
 |         |       http        |         |--------->| stdin    |
 |         |<=================>|         |<---------| stdout   |
 |         |   tcp connection  |         |<---------| stderr   |
 |         |                   |         |   pipe   |          |
 +---------+                   +---------+          +----------+
      |                                  \          /
      |                                   \        /
      |                                    \      /
   +-----+                                 +------+
   |     |                                 |      |
   |     |                                 |      |
   +-----+                                 +------+
    local                                   local
    file                                    file
    system                                  system


When the browser is asked to access a URL like this,

   http://example.com/WebApplications/MyWebApplication.class?color=red&size=small

the browser sends to the server an HTTP request like this.

GET  /WebApplications/MyWebApplication.class?color=red&size=small  HTTP/1.1
Host: example.com

The web server looks for the MyWebApplication.class resource in its local file
system and instead of sending that file to the browser, the server sees that
it is a class file so the server launches an instance of the JVM (java.exe) and
tells the JVM to execute the MyWebApplication class file. The server writes the
URL's query string to its stream connected to the JVM's standard input. The
results from the MyWebApplication program are sent over the JVM's standard
output stream to the web server. The web server sends those results over the
tcp connection to the browser as the response to the HTTP GET request. The
browser displays those results as a web page.

In the source code to the HttpServer_v1x.java web server program, the code
that handles Java web applications is in the method called doJavaCGI() which
is located in the file at around line number 950.


To run this web application, copy the package folder
   TimeZoneWebApp
into the root folder of the web server. Then access this URL.

      http://localhost:8080/TimeZoneWebApp/
