Week 7: Feb 23 - Mar 1, 2026

Unit III Transition: Request Handling to Session Tracking

Week Overview

This week continues Unit III by covering practical request handling in servlets and introducing state management with cookies.

Course Outcome: CO-3 (K3 - Application)
Duration: 1 week (3 lectures + 1 lab)
Lab: Browser Information, Objects, and Script Reuse
Home Assignment 2 Due: Feb 25

TipQuick Practice Quizzes (Lectures 19-21)

Lecture 19: Handling HTTP GET & POST Requests

NoteLecture Materials

Key Concepts

  • Purpose of doGet() and doPost() in servlet development
  • Reading parameters using request.getParameter()
  • Designing safe request processing flows

Typical Example

protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  String username = request.getParameter("username");
  response.getWriter().println("Welcome " + username);
}

Lecture 20: Redirecting Requests & Request Dispatching

NoteLecture Materials

Key Concepts

  • Difference between server-side forward and client-side redirect
  • Correct use of RequestDispatcher and sendRedirect()
  • Request attribute handling during navigation

Decision Rule

  • Use forward() when request attributes are needed on the next page
  • Use sendRedirect() after successful form submissions

Lecture 21: Session Tracking using Cookies

NoteLecture Materials

Key Concepts

  • Why session tracking is required in HTTP applications
  • Creating and reading cookies in servlet-based apps
  • Security and expiry considerations

Example

Cookie c = new Cookie("username", "student1");
c.setMaxAge(3600);
response.addCookie(c);

Lab 5: Browser Information, Objects, and Script Reuse

Objectives

  • Inspect browser/client details from request objects
  • Practice reusable JavaScript modules and utility methods
  • Integrate dynamic client behaviour with server-side flow

Activities

  1. Build a page that shows browser details and request headers.
  2. Store a temporary user value using cookies.
  3. Add reusable JavaScript functions for validation/formatting.
  4. Test both success and failure flows.

Key Takeaways

doGet() and doPost() solve different request needs
✅ Forward and redirect are both essential but used in different scenarios
✅ Cookies provide lightweight session tracking support

Next Week

Continue Unit III with: - Lecture 22: Session Tracking with HttpSession - Lecture 23: JSP Introduction and implicit objects - Lecture 24: JSP directives, actions, and custom tags