Servlets in Java: Web Server vs Application Server and URL Explained for Beginners

What are Servlets?

Servlets are Java programs that run on a server and handle client requests, usually coming from a web browser.
They are mainly used to build dynamic web applications.
Servlets run inside a server environment, which can be classified into:
  • Web Server
  • Application Server

🔹 Web Server

A Web Server is a server that contains:
  • Web Server Engine
  • Web Container

🔸 How a Web Server Works

  1. A client (browser) sends a request.
  2. The web server receives the request.
  3. The request is forwarded to the web container.
  4. The web container processes the request.
  5. A response is generated and sent back to the browser.

🔸 Role of Web Container

      Provides a runtime environment for web applications.
     Can run only web applications, such as:
  • Servlet applications
  • Spring applications
  • Struts applications

🔸 Web Server Limitations

  • Cannot run enterprise applications (EJB, distributed systems).

🔸 Examples of Web Servers

  • Apache Tomcat
  • GlassFish

🔹 Application Server

An Application Server is an advanced server that contains:
  • Web Container
  • Application Container

🔸 Components

  • Web Container → Runs web applications (Servlets, Spring, Struts)
  • Application Container → Runs enterprise applications (EJB)

🔸 Features

  • Handles request forwarding and response generation.
  • Supports both web and enterprise applications.
  • Used in large-scale enterprise systems.

🔸 Examples of Application Servers

  • WebLogic
  • WebSphere
  • JBoss

🔹 Difference Between Web Server and Application Server

Feature.                                  Web Server.                 Application Server
Runs Web Apps.                      ✅ Yes.                               ✅ Yes
Runs Enterprise Apps.           ❌ No.                                ✅ Yes
Containers.                         Web Container only.        Web + Application Container
Complexity.                              Simple.                             Advanced
Examples.                          Tomcat, GlassFish.             WebLogic, JBoss

🔹 URL (Uniform Resource Locator)

A URL is the address used to access resources on a server.

🔸 URL Structure

protocol://domain-name/resource-name?data

🔸 Components Explained

1. Protocol

  • Defines communication type
  • For web applications → http or https

2. Domain Name

    Combination of:
  • IP Address
  • Port Number
   Example: localhost:8080

3. Resource Name

  • Name of the web application or servlet
  • Example: /login

4. Data (Optional)

  • Sent from client to server
  • Format: key=value
  • Example: username=admin&password=123

🔹 Form Data in HTML

  • Data sent from an HTML form is called Form Data.
  • The key comes from the name attribute.
  • The value is entered by the user.

Example:

<input type="text" name="username">
  • username → key
  • User input → value

🔹 Real-Life Example

🔹 When you log in to a website:
  • Browser sends username and password via URL or request body.
  • Server (Tomcat/WebLogic) processes the request.
  • Servlet validates data.
  • Response (success or failure) is sent back to browser.

Comments

Popular posts from this blog

History of Java Programming Language | Features, Origin & Uses

Inheritance in Java: Types, Examples, and Explanation

Java Programming Features Every Beginner Should Know