Intro & Web Architecture
HTTP · Servlets · JSP · GET vs POST · Request & Response
🌐
Web Architecture — The Big Picture
Client Browser

Request
Server Web Server

Response
Client Gets content
Client — The browser. Sends the HTTP request.
Server — Receives the request, sends back a response.
// HTTP — HyperText Transfer Protocol
The shared language between client and server. A simple protocol built on top of TCP/IP, based entirely on the Request / Response model.
📄
Content Types & URL Anatomy
Static Pages
Pre-built HTML files, sent as-is. No processing needed.
Dynamic Content
Generated on-the-fly (Just-in-time) based on the request. Needs a helper app like a Servlet.
Key insight
A plain web server can't generate dynamic content alone → needs a Helper App like Servlets.
// URL Breakdown
Protocol
https://
Server Name
ibuild.dev
Port
:80
Path
/app/
Resource
index.html
// MIME Types — in the Response Header
text/html
image/jpeg
application/json
text/css
application/pdf
Port 80 = default HTTP port  ·  MIME tells the browser how to handle incoming content
⚔️
CGI vs Servlet
CGIServlet
LanguagePerl (typically)Java
Per requestSeparate ProcessLightweight Thread
Resource use❌ High (heavy)✅ Low (efficient)
Scalability❌ Poor✅ Excellent
CGI's fatal flaw
Spawns a separate process per request — extremely high resource consumption. Servlets use threads instead, sharing a single JVM instance.
Servlet vs JSP
Servlet
A Java class that handles requests on the server. Pure Java — great for logic, painful for HTML.
JSP
HTML with embedded Java code. Gets converted into a Servlet by the server automatically.
// The problem with Servlets
// Tedious HTML in Servlet — error-prone
out.println("<html>");
out.println("<body>Hello</body>"); // ← painful
out.println("</html>");
// The solution with JSP
<html>
<body> <%= new java.util.Date() %> </body>
</html>
// Clean, readable, JSP → compiled to Servlet by server
GET vs POST — Key Comparison
FeatureGETPOST
PurposeRetrieve dataSend data for processing
Data locationAppended to URLInside request body
Data size❌ Limited✅ Unlimited
Security❌ Visible in address bar✅ Hidden
Bookmarkable✅ Yes❌ No
Use casesSearch, fetching pagesPasswords, uploads, forms
// GET parameters format in URL
https://site.com/search?name=value&name2=value2
Everything after ? is the query string — fully visible to anyone.
📨
Anatomy of a Request & Response
HTTP Request contains
1
HTTP Method — GET or POST
2
URL — target resource path
3
Headers — e.g. User-Agent, Accept
4
Body — POST only (form data)
HTTP Response contains
1
Status Code200 OK / 404 Not Found
2
Content-Type — MIME type header
3
Headers — cache, cookies, etc.
4
Body — actual HTML / image / data
// Common Status Codes
200 OK  ·  301 Moved Permanently  ·  403 Forbidden  ·  404 Not Found  ·  500 Internal Server Error
🧠
The Golden Analogy
👤
Client
The customer — walks in, places an order (sends a request)
🤵
Server
The waiter — takes the order, delivers the response
👨‍🍳
Servlet
The chef — prepares the meal fresh, on demand
🥫
Static Page
Pre-packaged meal — ready to go, no preparation needed