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

Request dispatcher

saahil sinha
Ranch Hand

Joined: Apr 07, 2003
Posts: 68
I would like to know somethin about request dispatcher basically i do some processing in a servlet and forward output to a jsp.
What i would like to know is when the request gets forwarded to the jsp so like in the internet explorer address bar will u see the address of the servlet or jsp.I have a doubt out here coz in my address bar it shows me the address of the servlet though the output gets forwarded to jsp.Why is it so i thought forwarding to jsp means the jsp page should be displayed along with the address of the jsp page in the address bar not servlet.
Pls help
arul murug

Joined: Aug 08, 2002
Posts: 24
There are two ways we can forward to another resource.
One is response.sendRedirect() which changes the url in your browser and
Second is requestDispatcher.forward() which does not change the url in your browser.
In the First case webcontainer returns the control back to browser and browser sends the request to new url.
In the second case web container forwards the request to new url and it is transparent to the browser hence no change in the url in the browser.

SCJP2<br />SCWCD<br />UML & OOAD - IBM 486
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

There are two ways we can forward to another resource ... One is response.sendRedirect()

Not entirely accurate. The term "forward" is meant to mean that the request processing is passed along to another resource (such as a JSP or another servlet) within the context of the same request.
A "redirect" on the other hand, causes a new request to be generated.
And yes, in the case of the forward, since all passing-things-about happens on the server side, the browser has no idea what's going on an will continue to display the URL of the initial resource.
In the case of a redirect, the browser is instructed to create a new request to the new resource and so will update the URL to that resource.

[Asking smart questions] [About Bear] [Books by Bear]
arul murug

Joined: Aug 08, 2002
Posts: 24
You are right Bear ..
I meant two ways for transfering control to another resource. I should not have used the word "forward".
Thanks for the correction.
I agree. Here's the link:
subject: Request dispatcher
It's not a secret anymore!