Computer Science and IT‹›⌂ 0:00 studied

Module 12 · 15 min read · Free chapter

Web basics: HTML and client–server

In short

On the web, a browser client sends HTTP requests and a server responds, usually with HTML. A URL has scheme, host, port, path, query and fragment, with default ports 80 and 443. HTML gives structure, CSS style and JavaScript behaviour. Cookies and sessions add state to stateless HTTP, and HTTPS encrypts it.

What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: the counter and the queue

Picture a ration shop with one counter. Each customer arrives with a slip, the shopkeeper reads it, checks the register, and hands over the goods. The shopkeeper does not go looking for customers; he waits at the counter, and he serves whoever comes, one after another.

The web works the same way. Your browser is the customer: it sends a request, such as "give me the page /trains/search". A program called a web server waits for requests, finds or builds the page and sends back a response.

This pattern is called the client–server model. The client starts the conversation and the server answers. One server can serve thousands of clients at the same time, just as a large shop opens many counters.

Why it matters. Almost every service you use, from railway booking to online banking, is a client talking to a server. Once this picture is clear, URLs, HTML, cookies and web security all fit into it naturally.

Client–server and the three-tier model

In the client–server model, the server is a long-running program that listens for requests, and a client is any program that sends one. Servers usually run on powerful machines, while clients run on phones and laptops. The same machine can be a client for one service and a server for another.

Early business systems used a two-tier design: a desktop program on each clerk's computer talked directly to a central database. This was simple, but every client held the business rules, so changing one rule meant updating every computer, and every client needed direct access to the database.

Modern web systems use a three-tier architecture. The presentation tier is what the user sees, usually a browser. The application tier, also called the business-logic tier, runs on a web or application server and applies the rules, such as "a waiting-list ticket cannot be printed as confirmed".

The data tier is the database server, which stores the records. The browser never talks to the database directly; it talks only to the application tier, which talks to the database.

Tier Runs on Job
Presentation The user's browser or app. Shows pages and collects input.
Application (business logic) A web or application server. Applies the rules and builds responses.
Data A database server. Stores and retrieves records.

Why it matters. Separating tiers means the rules change in one place, more application servers can be added when traffic grows, and the database stays hidden from the internet. Exams ask which tier does what, and why three tiers are safer and easier to scale than two.

URLs and the HTTP request and response

How does the browser know which server to ask and what to ask for? It reads the URL (uniform resource locator). The general form is scheme://host:port/path?query#fragment.

Worked example 1: reading a URL. Take https://www.example.com:8443/trains/search?from=PNBE&to=NDLS#results. The scheme is https, the host is www.example.com, and the port is 8443. The path is /trains/search, the query holds two pairs, from=PNBE and to=NDLS, joined by &, and the fragment results tells the browser which part of the page to scroll to.

If the port is left out, the browser uses the default: 80 for http and 443 for https. The fragment is never sent to the server; it stays in the browser. The host name is turned into an IP address by DNS before the connection opens.

The browser then sends an HTTP request: a method, the path, a version and headers such as Host. The server answers with an HTTP response: a status code, headers such as Content-Type, and the body, usually HTML. The full message format and the role of DNS are covered with the other application layer protocols, but four methods and four code groups are enough here.

Item Meaning
GET Fetch a resource; data, if any, goes in the URL.
POST Send data to be processed, such as a form, in the body.
PUT and DELETE Replace or remove a resource.
2xx, e.g. 200 OK The request succeeded.
3xx, e.g. 301 The resource has moved; go to the new URL.
4xx, e.g. 404 The client asked for something wrong or missing.
5xx, e.g. 500 The server failed while handling the request.

HTTP is stateless: each request is handled on its own, and the server does not remember the previous one. This keeps servers simple and fast, but it creates a problem for logins and shopping carts, which a later section solves with cookies.

Worked example 2: counting round trips. A page has one HTML file that refers to 5 more objects (a style sheet, a script and 3 images), and the round-trip time is 50 ms. With non-persistent HTTP, each of the 6 objects needs one round trip to open a TCP connection and one to fetch it, so the time is about 6×2×50=6006 \times 2 \times 50 = 600 ms. With one persistent connection and requests sent one at a time, it is (1+6)×50=350(1 + 6) \times 50 = 350 ms, ignoring transmission time.

Why it matters. Every web question starts from the URL and the request. Status codes, default ports and the GET and POST difference are among the most asked one-mark facts in IT officer papers.

HTML: document structure, common tags and forms

The body of most responses is written in HTML (HyperText Markup Language). HTML is not a programming language; it marks up content with tags that tell the browser what each part is. Most tags come in pairs, such as <p> and </p>, and an element can carry attributes, such as href in a link.

<!DOCTYPE html>
<html>
  <head>
    <title>Train search</title>
  </head>
  <body>
    <h1>Find a train</h1>
    <p>Enter the station codes.</p>
    <form action="/trains/search" method="get">
      <input type="text" name="from" placeholder="From">
      <input type="text" name="to" placeholder="To">
      <input type="submit" value="Search">
    </form>
    <a href="/help">Help</a>
  </body>
</html>

The first line tells the browser this is an HTML5 document. The html element holds two parts. The head holds information about the page, such as its title and links to style sheets, and the body holds what the user sees.

Common tags are headings h1 to h6, paragraphs p, links a with href, images img with src and alt, lists ul (bulleted) and ol (numbered) with items li, and tables built from table, tr (row), th (heading cell) and td (data cell). The tags div and span group content for styling, where div is a block and span is inline. Some tags, such as img, br and input, are empty and have no closing tag.

A form collects input. Its action attribute names the URL that receives the data, and its method is get or post. Each input has a type, such as text, password, email, number, radio, checkbox or submit, and a name that becomes the key in the data sent.

Worked example. If a user types PNBE and NDLS in the form above and presses Search, the browser requests /trains/search?from=PNBE&to=NDLS, because the method is GET. With method="post" the same pairs would travel in the request body instead, and the URL would stay /trains/search.

Why it matters. Every web page, however fancy, is HTML underneath. Questions on the head and body, empty tags, list and table tags, and GET against POST in forms are very common in RRB JE IT papers.

CSS, JavaScript, and static versus dynamic pages

A page has three layers, and each has its own language. HTML gives the structure and content, CSS (Cascading Style Sheets) gives the presentation, such as colours, fonts and layout, and JavaScript gives the behaviour. Keeping them separate means a designer can restyle the whole site by changing one style sheet.

CSS can be written in three places. Inline CSS sits in a style attribute on one element, internal CSS sits in a style element in the head, and external CSS sits in a separate .css file linked from the head. When rules conflict, the "cascade" decides: an inline rule beats internal and external rules, and a more specific selector, such as an id, beats a less specific one, such as a tag name.

JavaScript is the programming language that runs inside the browser. It reads and changes the page through the Document Object Model (DOM), a tree of objects that mirrors the HTML. It also reacts to events such as a click or a key press, so it can check that a form field is not empty before the form is sent, without any trip to the server.

Now, who builds the page? A static page is a fixed file stored on the server and sent the same to every visitor, such as an "About us" page. A dynamic page is built for each request. Server-side code (for example PHP, Java servlets, Python or Node.js) can read the database and build a page showing your own bookings, while client-side JavaScript can change the page after it arrives.

Point Static page Dynamic page
Content The same for every visitor. Built for each request or user.
Server work It only sends a stored file. It runs code and often reads a database.
Example A notice or an "About us" page. A PNR status or bank statement page.

Why it matters. Exams ask which language does which job and where it runs. The key facts are that CSS controls presentation, JavaScript runs in the browser, and dynamic pages are built on the server or in the browser at request time.

Cookies, sessions, REST and JSON

HTTP is stateless, so how does a booking site remember that you logged in two pages ago? The answer is the cookie. After a successful login, the server's response carries a header such as Set-Cookie: sid=7f3a, and the browser stores this small piece of text.

On every later request to the same site, the browser sends it back in a Cookie: sid=7f3a header. The server sees the value and knows who you are. A cookie can carry an expiry time, and it can be marked so that it is sent only over HTTPS.

A session builds on this. The cookie holds only a random session ID, while the real data, such as your name and the contents of your cart, stays in a session table on the server. This is safer than storing the data in the cookie itself, because the user cannot read or change what is on the server.

Phone apps and modern pages often do not want whole HTML pages from the server; they want data. A REST API gives each resource its own URL and uses the HTTP methods on it: GET /trains/12345 fetches a train, POST /bookings creates a booking, and DELETE /bookings/881 cancels one. Each request carries everything the server needs, so the server keeps no client state between requests, just as HTTP itself is stateless.

The data usually travels as JSON (JavaScript Object Notation), a plain-text format. An object is a set of name–value pairs inside braces, a list is an ordered set of values inside square brackets, and values can be strings, numbers, true, false, null, objects or lists.

{
  "number": 12345,
  "name": "Sample Express",
  "days": ["Mon", "Wed", "Fri"],
  "running": true,
  "delay_min": null
}

Here days is a list of three strings, running is a true-or-false value and delay_min is empty. Any language, whether Java, Python or JavaScript, can read this text and turn it into its own objects.

Why it matters. Cookies and sessions explain how logins work on a stateless protocol, and REST with JSON is how nearly every app talks to its server today. Exams ask where session data is kept, which header sets a cookie, and what JSON looks like.

Web security basics: HTTPS and common attacks

Plain HTTP sends everything as readable text, so anyone on the same Wi-Fi or along the route could read a password or change a page. HTTPS fixes this by running HTTP inside an encrypted TLS connection, by default on port 443. The server also shows a certificate, so the browser can check that it is really talking to the bank and not to an impostor.

HTTPS protects data on the way, but it does not protect a badly written application. Two attacks are worth knowing by name. In SQL injection, text typed into a form is pasted straight into a database query and runs as part of it, so an attacker may read or delete records.

The defence is to use parameterised queries, which keep the user's input as data and never as part of the query's code, and to validate all input on the server. In cross-site scripting (XSS), an attacker gets a script stored in a page that other users then see, and the defence is to escape user content before showing it.

Why it matters. Exams for IT officer posts often ask what HTTPS adds over HTTP and which attack matches a description. Remember the pairs: HTTPS gives encryption and server identity, parameterised queries stop SQL injection, and escaping output stops XSS.

Descriptive lens: how written papers ask this

GATE asks about HTTP only as a network protocol, but written papers for IT officer posts, state Assistant Programmer exams and university tests ask about the web in four ways:

  1. Explain the client–server and three-tier models with a labelled diagram.
  2. Write a small HTML page or form and explain its tags and attributes.
  3. Compare pairs such as GET and POST, static and dynamic pages, or cookies and sessions.
  4. Describe how a modern app talks to its server through a REST API with JSON, and how the exchange is secured.

Practice questions (our own, not previous-year questions).

  1. Explain the three-tier architecture of a railway reservation website. Why is it preferred over a two-tier design? (15 marks)
  2. Write an HTML form that accepts a name, an email address and a password, and explain why it should use POST. (10 marks)
  3. HTTP is stateless. Explain how cookies and sessions let a website keep a user logged in. (10 marks)

Answer plan for question 3.

  • Begin by explaining that a stateless protocol handles each request on its own, so the server cannot tell that two requests came from the same user.
  • Explain that after login the server sends a Set-Cookie header and the browser returns the value in a Cookie header on every later request.
  • Explain that in a session the cookie holds only a random session ID, while the user's data stays in a table on the server.
  • Note the safeguards, which are sending the cookie only over HTTPS, setting an expiry, and creating a new session ID at login.
  • Conclude that cookies and sessions add state on top of HTTP without changing the protocol itself.

Quick revision

  • A client sends requests and a server waits for them and responds, and one server serves many clients.
  • The three tiers are presentation, application (business logic) and data, and the browser never talks to the database directly.
  • A URL is scheme://host:port/path?query#fragment, and the default ports are 80 for http and 443 for https.
  • HTTP is stateless, and its status codes are 2xx success, 3xx redirection, 4xx client error and 5xx server error.
  • An HTML page has a head with the title and a body with the content, and img, br and input have no closing tag.
  • A form's action names the receiving URL, GET sends data in the URL, and POST sends it in the body.
  • HTML gives structure, CSS gives presentation, and JavaScript gives behaviour in the browser through the DOM.
  • A static page is a fixed file, while a dynamic page is built per request on the server or in the browser.
  • Cookies are set with Set-Cookie and returned with Cookie, and session data stays on the server.
  • REST gives each resource a URL and uses HTTP methods, and JSON carries the data.
  • HTTPS is HTTP over TLS, and parameterised queries stop SQL injection.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 15 answered

  1. In the client–server model, which side starts the communication?

  2. In a three-tier web application, the business rules run in the:

  3. In https://www.example.com:8443/trains/search?from=PNBE#results, which part is NOT sent to the server?

  4. The default port for https is:

  5. The HTTP status code 404 belongs to which class?

  6. A page has 1 HTML file and 5 embedded objects. The RTT is 50 ms. Ignoring transmission time, non-persistent HTTP needs about:

  7. In an HTML document, the title element belongs inside:

  8. Which HTML tag has no closing tag?

  9. A form with method="get" and fields from and to is submitted with PNBE and NDLS. The data travels:

  10. Which language mainly controls the colours, fonts and layout of a web page?

  11. A page that shows each user's own bank statement, built from a database for every request, is:

  12. In session-based login, where is the user's session data normally kept?

  13. Which is valid JSON?

  14. Which measure prevents SQL injection?

  15. Where does the GATE 2026 CS syllabus mention HTTP?

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

What is the difference between GET and POST?

GET sends form data in the URL query string, while POST sends it in the request body, so POST suits passwords.

What are the three tiers of a web application?

Presentation (the browser), application or business logic (the server) and data (the database).

What is the difference between a cookie and a session?

A cookie is stored in the browser; in a session it holds only an ID, while the user's data stays on the server.

What does HTTPS add to HTTP?

It runs HTTP over encrypted TLS, usually on port 443, and the server proves its identity with a certificate.

More in this module: Software engineering, OOP and web

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Computer Science and Information Technology (CS) syllabus, IIT Guwahati
  2. NPTEL Software Engineering (IIT Kharagpur, 106105182): client-server and layered architecture