Forums Register Login

Puzzle:Difference of redirect method?

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Thanks a lot,you are so kind!
Pay attention! Tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 849 times.
Similar Threads
Finalization Method
NX: When should I throw DuplicateKeyException?
garbage collection
Sharpen your Pencil - Page 323 in HFEJB
Changin font in a JTextArea
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:16:17.