Web applications are hot!!!
With web apps, you can deliver your app to anyone with a browser and can be used by millions of users worldwide.
Today’s users expect sites that are dynamic, interactive and custom-tailored.
Every body wants a web site. (flexible and scalable architecture)
The web consists of gazillions of clients(using browsers like Mozilla or Safari) and servers (using Web Server like Apache) connected through wires and wireless networks.
Our goal is to build a web application that clients around the globe can access.
What does your web server do??
A web server takes a client request and gives something back to the client.
A web browser lets a user request a resource. The Web server gets the request, finds the resource and returns something to the user. Sometimes, the response is an HTML page. Sometimes it’s a picture of a sound file or a even a PDF document.
If the resource is not found, you get ‘404 Not Found’ error.
what does a Web client do??
A web client lets the user request something on the server, and shows the user the result of the request.
The browser is the piece of software that knows how to communicate with the server. The browser’s other big job is interpreting the HTML code and rendering the web page for the user.
Clients and Servers know HTTP and HTML.
HTTP is the protocol that clients and servers use on the web to communicate.
The Server uses HTTP to send HTML to the client.
HTML tells the browser how to display the content to the user.
What is HTTP Protocol??
HTTP runs on top of TCP/IP. It has web-specific features.
The structure of an HTTP conversation is a simple Request/Response sequence; a browser requests, and a server responds.
Key elements of a Request :
- HTTP method (GET or POST)
- the page to access ( a URL)
- Form parameters
Key elements of a Response :
- A status code
- Content-type
- the Content
HTML is part of the HTTP response. HTTP adds header information to the top of whatever content is in the response. An HTML browser uses that header info to help process the HTML page.
HTTP request method tells the server the kind of request that’s being made and how the rest of the message will be formatted. ex, GET, POST, PUT, DELETE, etc
GET is a simple request, it’s job is to ask the server to get a resource.
POST can send user data.

Anatomy of an HTTP GET request :

Anatomy of an HTTP POST request :
HTTP POST requests are designed to be used by the browser to make complex requests on the server. The data to be send to the user is known as the “message body” or “payload” and can be quite large.

Anatomy of an HTTP response :
An HTTP response has both a header and a body. The header info tells the browser about the protocol being used, whether the request was successful, and what kind of content is included in the body.
The body contains the contents for the browser to display

How web request-response works?? All pieces together.

URL :

A TCP port is just a number.
Web servers love serving static web pages. A static page just sits there in a directory. The server finds it and hands it back to the client as is. Every client sees the same thing.
Problem :
But some times you need more than just static content. We need to perform some kind of computations at the web server like interacting with the database or platforms or processing some kind of business logic.
But the web server application can’t do those computations. It requires another helper application on the server, which can handle this task.
Two things the web server alone won’t do :
- Dynamic Content
the web server application serves only static pages, but a separate “helper” application that the web server can communicate with can build non-static, just-in-time pages.
A dynamic page could be anything from a catalog to a weblog or even just a page that refreshes every second to display current time.
Servlets and CGI both play the role of a helper app in the web server.
- Saving data on the server
Just-in-time pages don’t exist before the request comes in. It’s like making an HTML page out of thin air. The request comes in, the helper app writes the HTML and the web server gets it back to the client.
Web Servers are good at serving static HTML pages, but if you need dynamically generated data in the page, you need some kind of helper app that can work with the server.
Servlets and CGI both play the role of a helper app in the web server.