Unit III Block 1: Servlet Foundations
Lectures 17-20 - servlet architecture, lifecycle, request handling, and dispatching
Block Overview
This block starts Unit III and moves from client-side pages to server-side request processing. The focus is on what a servlet is, how the container manages it, and how requests are received, processed, and routed.
Course Outcome: CO-3 (K3 - Application)
Lectures Covered: 17-20
Theme: Core servlet programming
Lecture 17: Servlet Overview & Architecture
Core Ideas
- What a servlet container does in a Java web application
- How browser requests reach a servlet
- Role of
web.xml, annotations, and deployment descriptors - Basic request-response flow in server-side applications
Typical Request Flow
Focus Points
- Difference between static page delivery and dynamic response generation
- Why servlets are used for business logic and request processing
- Where JSP fits relative to servlets
Lecture 18: Servlet Interface & Life Cycle
Lifecycle Methods
init()for one-time startup workservice()for request handlingdestroy()for cleanup before shutdown
Lifecycle Sequence
Why It Matters
- Explains when servlet objects are created
- Helps avoid repeated setup work inside request processing
- Introduces thread-safety concerns in shared servlet instances
Lecture 19: Handling HTTP GET & POST Requests
Request Handling
doGet()for safe reads and page fetchesdoPost()for form submission and state-changing operations- Parameters read through
request.getParameter()
Example
Comparison
- GET data is visible in URL and suitable for retrieval
- POST sends data in request body and is used for submit/update flows
Lecture 20: Redirecting Requests & Request Dispatching
Forward vs Redirect
forward()keeps processing on the server and usually preserves request datasendRedirect()tells the browser to make a fresh request- Redirect changes the URL; forward usually does not
Example
Decision Rule
- Use redirect after successful submit flows
- Use forward when the next page needs the current request attributes
Key Takeaways
- A servlet container manages creation, execution, and cleanup of servlets
doGet()anddoPost()solve different request scenarios
- Request dispatching controls how the user moves between server resources
- This block prepares the shift to session management and JSP
Next Block
Unit III continues with cookies, HttpSession, JSP basics, and JSP tags.