File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Use of getRequestDispactcher() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Use of getRequestDispactcher()" Watch "Use of getRequestDispactcher()" New topic

Use of getRequestDispactcher()

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
Hello Ranchers,

What is use of getRequestDispactcher() in jsp, please explain with example?
What makes it differ from forward and redirect methods?

Thanks<br />Dinesh
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

As Java code should never be put into JSPs, there is no use of RequestDispatcher in JSPs.

It is, however, used under-the-covers to perform includes and forwards. But as a JSP author, one does not need to worry about that.

[Asking smart questions] [About Bear] [Books by Bear]
Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
RequestDispatcher is in servlet , what is its use, please explain
David Newton

Joined: Sep 29, 2008
Posts: 12617

It's what allows us to do includes and forwards. Redirects are done with the response.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 689


Actually at servlet side RequestDispacher and sendRedirect use for forwarding your request just they use to forward methodology is difference....

1 ) Using request dispatcher you can for ward your request but without knowing your client so it happens at server side. So, you are not see that request in browser.

2 ) While send redirect also use for the same use but it happens at client side... and new request url see at clents browser windows.........

Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
I agree. Here's the link:
subject: Use of getRequestDispactcher()
jQuery in Action, 3rd edition