Skip to content

Topic 3: Web Component ‐ Servlet

Zhamri Che Ani edited this page Apr 10, 2026 · 1 revision

Goal

To enable students to understand and develop dynamic web applications using Java Servlets, including handling client requests, processing data, and managing sessions.

🎯 Learning Objectives

Students should be able to:

  1. Explain the role of Servlets in Java web applications
  2. Create and configure a basic Servlet
  3. Use the Servlet API to handle HTTP requests and responses
  4. Process form data submitted from HTML
  5. Implement session tracking in web applications
  6. Connect Servlets with a database (basic level)

📌 Topics to Cover

  1. Introduction to Servlets
    • What is a Servlet
    • Servlet lifecycle
  2. Creating and Running Servlets
    • Deployment in web container (Tomcat)
    • Servlet configuration
  3. Servlet API
    • HttpServlet
    • doGet() and doPost() methods
    • Request and Response objects
  4. Handling HTML Forms
    • Getting form parameters
    • Sending responses to client
  5. Session Tracking
    • HttpSession
    • Cookies (basic concept)
  6. Database Programming in Servlets
    • Basic JDBC integration with Servlet

🛠️ Hands-on Activity

Activity: Student Registration System using Servlet

Students are required to:

  1. Create HTML Form (Frontend). Fields:
    • Name
    • Email
    • Program
  2. Create Servlet (Controller)
    • Create a Servlet class (e.g., RegisterServlet)
    • Handle form submission using:
      • doPost() method
  3. Process Form Data
    • Retrieve data using:
      • request.getParameter()
    • Display output:
Registration Successful!
Name: Ali
Email: ali@email.com
Program: Software Engineering
  1. Implement Session Tracking
    • Store user name in session:
      • HttpSession session = request.getSession();
    • Display welcome message:
Welcome, Ali!
  1. Database Integration
    • Save student data into database using JDBC

Expected Output

Students should produce:

  1. HTML form page
  2. Servlet class
  3. Output page showing submitted data
  4. Session-based welcome message

📚 Suggested Readings

  1. Oracle Servlet Documentation https://jakarta.ee/specifications/servlet/
  2. Apache Tomcat Documentation https://tomcat.apache.org/
  3. Java Servlet Tutorial (tutorialspoint) https://www.tutorialspoint.com/servlets/index.htm
  4. JDBC + Servlet Integration Guide
  5. https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaServlets.html
  6. https://www.geeksforgeeks.org/java/introduction-java-servlets/

Clone this wiki locally