aspose file tools*
The moose likes JSP and the fly likes Diff Between redirect & forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Diff Between redirect & forward" Watch "Diff Between redirect & forward" New topic
Author

Diff Between redirect & forward

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
TV KUMAR
Greenhorn

Joined: Mar 18, 2004
Posts: 6
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.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Diff Between redirect & forward