• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the main difference between "forward" and "sendRedirect"?
Thanks in advance.
Muhammad Shahzad
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic