Redirect vs. Request Dispatch

image with no caption

When a servlet does a redirect, it’s like asking the client to call someone else instead. In this case, the client is the browser, not the user. The browser makes the new call on the user’s behalf, after the originally-requested servlet says, “Sorry, call this guy instead...”

The user sees the new URL in the browser.

image with no caption

When a servlet does a request dispatch, it’s like asking a co-worker to take over working with a client.

The co-worker ends up responding to the client, but the client doesn’t care as long as someone responds.

The user never knows someone else took over, because the URL in the browser bar doesn’t change.

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.