File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Muhammad Shahzad
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the main difference between "forward" and "sendRedirect"?
Thanks in advance.
Muhammad Shahzad
 
Helen Crosbie
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic