Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

control transfer

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,
can you tell me the difference among response.sendRedirect(),requestdispatcher.include() and requestdispatcher.forward().
in a 10 lines servlet program,if i am calling any one of this on the 5th line,whether the remaining lines will be executed or not?
thanks a lot,
yours
balraj
 
zeus
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi balraj
response.sendRedirect() -- this sends a new request to the page which you have request,since its a new request the objects are not available in the redirected page which has been created in the earlier page before redirected.and also you can see the redirected page loaded in the url(the page name appears in the url).and you cursor never returns to the oldpage, where you have redirected from...
requestdispatcher.include() -- the method name itself gives you the answer..here it includes the page whatever you have requested.say you wanna include an html form inbetween a jsp page then use this, so that the html form is included in this page.
requestdispatcher.forward() -- here the request goes to the next page so the objects created are available to the next page also..here it doesn't go for new page request instead it forwards the request to next page.and also the earlier page name will be displayed in the url, even if your cursor goes to next page(ie, the forwarded page).here after finishing the task you can bring back the cursor to the earlier page from where you made the request..
i hope this helps you
all the best
zeus
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note that The Java Ranch has a naming policy, described here and "zeus" is not a valid name. Please choose one which meets the requirements.
I have mentioned this to you before. Please choose a new name as soon as possible, as "zeus" will be disabled very soon.
Thanks.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear zeus,
thanks for your reply.you cleared my doubts well.
thanks a lot,
yours
balraj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic