This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes jsp forward  and sendRedirect( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp forward  and sendRedirect("")...?" Watch "jsp forward  and sendRedirect("")...?" New topic
Author

jsp forward and sendRedirect("")...?

Muhammad Shahzad
Ranch Hand

Joined: Feb 17, 2002
Posts: 36
What is the main difference between "forward" and "sendRedirect"?
Thanks in advance.
Muhammad Shahzad
Helen Crosbie
Greenhorn

Joined: Mar 11, 2003
Posts: 26
Hi,
'Forward' will send the original request object to the new page which means you'll see the original URL in the browser, so a refresh might look odd. You will be able to use all the parameters from the original request at the new page.
'sendRedirect()' sends a 'temporary redirect response to the client' but you must use an absolute URL.
Sazzad Rafique
Greenhorn

Joined: Jul 29, 2003
Posts: 5
In case of sendRedirect(), the browser issues a completely new request and any objects that are stored as request attributes before the redirect occurs, will be lost.
But using jsp forward objects can be stored into the request and passed along for the next resource to make use of.
Another difference is performance of forward is better than redirect since in case of a forward there is no communication with the client and the whole process occurs within the web container .
Muhammad Shahzad
Ranch Hand

Joined: Feb 17, 2002
Posts: 36
Thanks a lot Helen and Secl for your good explanations. I got it.
One thing more...does Jsp and Servlets can share the same request. I mean are same session level varibles accessible to the servlets that were set into a Jsp page.
Thanks.
M.Shahzad
Sazzad Rafique
Greenhorn

Joined: Jul 29, 2003
Posts: 5
Yes it is possible. Its also possible doing the other way round, i mean you can set a session level variable from servlet and access it from jsp.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp forward and sendRedirect("")...?
 
Similar Threads
difference between forward and include
servlets
URGENT!!!!
what is the difference between forward and sendredirect
which one is fast