Lecture 20: Redirecting Requests & Request Dispatching

BMC201 - Web Technology

Mr. Prashant Kumar Nag

2026-02-26

Lecture 20

Redirecting Requests & Request Dispatching

Week 5 | Unit III: Web App Development (Servlets + JSP)
BMC201 - Web Technology
Mr. Prashant Kumar Nag, Assistant Professor

Learning Objectives


  • Explain redirect vs request dispatching
  • Use sendRedirect and RequestDispatcher APIs
  • Select proper navigation strategy

Prerequisites


  • Java basics: classes, methods, objects, and exception handling
  • HTTP request-response fundamentals from Unit I/II web context
  • Revision of Lecture 19 before moving into Redirecting Requests & Request Dispatching

Syllabus Mapping


  • Unit III topic focus: Redirecting Requests & Request Dispatching
  • CO alignment: implementation understanding + architecture reasoning
  • Assessment alignment: short definitions + long implementation/design questions

Agenda


  • 5-minute recap from previous lecture
  • Concept deep dive: Redirecting Requests & Request Dispatching
  • Code/configuration walkthrough and output analysis
  • Debug checklist and exam-oriented summary

Introduction


Redirect creates a new request; forward reuses the same request.

Think About It


Do you need browser URL to change after processing?

Redirect vs Forward


sendRedirect(): client-side new request, forward(): server-side transfer

Code Walkthrough


response.sendRedirect("dashboard");

RequestDispatcher rd = request.getRequestDispatcher("/result.jsp");
request.setAttribute("status", "ok");
rd.forward(request, response);

Memory Booster


Syllabus memory points for Redirecting Requests & Request Dispatching:

  • Core recall: sendRedirect() and RequestDispatcher.forward()
  • Exam compare: Client-side redirect vs server-side forward
  • Practical anchor: Build login flow with redirect success and forward failure path

Live Demo


Live implementation for Redirecting Requests & Request Dispatching:

?? Open Demo: Lecture 20 - Redirecting Requests & Request Dispatching

Demo checklist: - implement the key flow for this lecture - verify expected output for one success case - trigger one failure case and explain the fix

Resources & References


Structured Debug Checklist


  1. verify the primary API usage for Redirecting Requests & Request Dispatching is correct (imports, method names, config)
  2. check request/bean/session flow and object lifecycle assumptions
  3. inspect server logs for the first exception (not just the final symptom)
  4. reproduce one failing case and one passing case before finalizing fixes

Exam Preparation Questions: Short


  • Define Redirecting Requests & Request Dispatching with one practical use case.
  • Write/identify the key API or construct: sendRedirect() and RequestDispatcher.forward().
  • Differentiate: Client-side redirect vs server-side forward.
  • Mention one common implementation error and correction.

Exam Preparation Questions: Long


  • Explain Redirecting Requests & Request Dispatching with architecture/flow and implementation steps.
  • Write a structured answer comparing two approaches used in this topic.
  • Discuss debugging strategy for this topic with likely failure points.

Practice Task


  • Implement: Build login flow with redirect success and forward failure path.
  • Add console/log output to validate flow step-by-step.
  • Document one bug you encountered and the exact fix.

Checklist


Can you:

  • explain Redirecting Requests & Request Dispatching in your own words?
  • implement a basic example end-to-end?
  • identify and fix one common runtime issue?

Next Lecture


  • Topic: Lecture 21 - Session Tracking using Cookies
  • Preparation required: revise this lecture summary and code walkthrough

Questions?

Next: Lecture 21