• Post Reply Bookmark Topic Watch Topic
  • New Topic

Puzzle:Difference of redirect method?  RSS feed

 
pengpeng lin
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,Can anybody help me :

What is the diffrence among the <jsp:forward>,RequestDispatcher(request,response) and the

sendRedirect method?

When and where to use them?
 
Anupam Bhatt
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well a google search for this would have given you enough information,
but still here is what i know:

First difference between Requestdispatcher's sendredirect and Forward.

1. In case of request dispatcher's sendredirect a "New Request is generated".
that means the request object is totally new and all the parameters in the old request object are lost.
For example: if the existing reuqest had a parameter as "name=pengpeng", after you do a redirect the new request would not have this parameter.

2. In case of request dispatcher's forward the same request object is forwarded to the new resource. so even after a rd.forward [rd can be a request dispatcher object], the name=pengpeng will be available.

3. Now the <jsp.forward> tag. This tag can be used to cause a client request to be "forwarded" to another resource.
Whenever the <jsp.forward> tag is encountered by the JSP engine, the engine forwards the request that was sent to the JSP file to another file. The JSP engine doesn't process the remainder of the current JSP file.
Here again the same request object is maintained.

In my view jsp:forward and rd.forward are almost the same.

Now the usage of these:

Consider a scenario in which page refresh would cause the same request object to be sent again. [letz say a credit card payment page]. So letz say an impatient user refreshes the page again before the transaction could be completed, the rd.forward would cause the same request to be sent again. But if you use sendredirect this can be avoided.

Consider a scenario where you need the same request paramater accross pages [letz say a unique customer no.]you should do a request forward.

This answer is purely based on my understanding, anybody please correct me if i am worng.

Thanks,
Anupam Bhatt
[ December 25, 2005: Message edited by: Anupam Bhatt ]
 
pengpeng lin
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot,you are so kind!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!