Topic 3: Web Component ‐ Servlet - zhamri/CSC584-Enterprise_Programming GitHub Wiki
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:
- Explain the role of Servlets in Java web applications
- Create and configure a basic Servlet
- Use the Servlet API to handle HTTP requests and responses
- Process form data submitted from HTML
- Implement session tracking in web applications
- Connect Servlets with a database (basic level)
📌 Topics to Cover
- Introduction to Servlets
- What is a Servlet
- Servlet lifecycle
- Creating and Running Servlets
- Deployment in web container (Tomcat)
- Servlet configuration
- Servlet API
- HttpServlet
- doGet() and doPost() methods
- Request and Response objects
- Handling HTML Forms
- Getting form parameters
- Sending responses to client
- Session Tracking
- HttpSession
- Cookies (basic concept)
- Database Programming in Servlets
- Basic JDBC integration with Servlet
🛠️ Hands-on Activity
Activity: Student Registration System using Servlet
Students are required to:
- Create HTML Form (Frontend). Fields:
- Name
- Program
- Create Servlet (Controller)
- Create a Servlet class (e.g., RegisterServlet)
- Handle form submission using:
- doPost() method
- Process Form Data
- Retrieve data using:
- request.getParameter()
- Display output:
- Retrieve data using:
Registration Successful!
Name: Ali
Email: [email protected]
Program: Software Engineering
- Implement Session Tracking
- Store user name in session:
- HttpSession session = request.getSession();
- Display welcome message:
- Store user name in session:
Welcome, Ali!
- Database Integration
- Save student data into database using JDBC
Expected Output
Students should produce:
- HTML form page
- Servlet class
- Output page showing submitted data
- Session-based welcome message
📚 Suggested Readings
- Oracle Servlet Documentation https://jakarta.ee/specifications/servlet/
- Apache Tomcat Documentation https://tomcat.apache.org/
- Java Servlet Tutorial (tutorialspoint) https://www.tutorialspoint.com/servlets/index.htm
- JDBC + Servlet Integration Guide
- https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaServlets.html
- https://www.geeksforgeeks.org/java/introduction-java-servlets/