Meaningless Drivel is fun!
The moose likes JSP and the fly likes SendRidirect vs RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "SendRidirect vs RequestDispatcher" Watch "SendRidirect vs RequestDispatcher" New topic

SendRidirect vs RequestDispatcher

Sandipan Mukherjee

Joined: Dec 07, 2006
Posts: 8
Tell me the difference between response.sendRedirect and requestDispatcher.forward with respect to session?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

With respect to session, there is little difference between the two.

In general, they are very different.
requestDispatcher.forward takes place on the server, within one request cycle.
The client (browser) has no idea that this has taken place.

response.sendRedirect works by sending a 302 header (along with a Location header), suggesting that the browser make a brand new request.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

The client (browser) has no idea that this has taken place.

you can notice, in browser URL bar, URL will not change while you are doing forward but if you do redirect you can see that changing.

Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />
I agree. Here's the link:
subject: SendRidirect vs RequestDispatcher
It's not a secret anymore!