Forums Register Login

Diff Between redirect & forward

+Pie Number of slices to send: Send
What's the difference between response.redirect() & getRequestDispatcher.forward();
Can someone help me out by giving a example where we can use one but not the other.
Thnx.
+Pie Number of slices to send: Send
response.sendRedirect() method is used to just redirect the request. By this method the request variables will not be available in the forwarded page. Where as for request despatching they will be available.
Suppose u have a HTML text field by the name 'name'.Suppose the form's action page is a servlet 'A'. After the form is submitted, in servlet 'A', u can access the value entered in the text field by using request.getParameter("name"). Suppose u have redirected the request from 'A' to servlet 'B'. In 'B' u cannot access the parameter "name" as u did in servlet 'A'. U can access it only if u had despatched it.
When u use sendRedirect(), the response is committed to the browser and it is the browser which calls the second servlet.
+Pie Number of slices to send: Send
Does it has any thing to do with the Application context.If no, then
What if i want to forward or redirect some request to a jsp/servlet of another context.
+Pie Number of slices to send: Send
"Nirant",
We're pleased to have you here with us in the JSP forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
Forum Bartender
+Pie Number of slices to send: Send
TV KUMAR,
JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.
I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.
thanks,
bear
JSP Forum Bartender
I've read about this kind of thing at the checkout counter. That's where I met this 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 1032 times.
Similar Threads
Game on SQL
EJB Server provider vs EJB Container provider
Difference between == and .equals
PMP & Prince2
What is the diffrence between jsp:forward and response.sendRedirect
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:01:55.