• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request dispatcher

 
saahil sinha
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64180
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
hth,
bear
 
arul murug
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic