• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the diffrence between jsp:forward and response.sendRedirect

 
Ashish Kothari
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody tell diffrence between between jsp:forward and response.sendRedirect ?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServletResponse.sendRedirect(String url) sends a HTTP response message to the client (e.g. a web browser) saying "go to this URL instead".
<jsp:forward ...> is actually a call to HttpServletRequest.forward(String url), which passes the request object within the server to another request processor (either a servlet or a jsp). In other words, the client is not aware that the request is being forwarded anywhere.
Does this help?
[ May 18, 2003: Message edited by: Lasse Koskela ]
 
suresh guru
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the above reply do u mean in sendRedirect the request object wont be available to the processor(ie servlet/JSp)???
ie the attributes set in the req wont be available???
 
Ashish Kothari
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,I think you are right
 
Kaustubh Patil
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh,
During the sendRedirect() a new request object is created. Natuarally you don't get any attributes that exist in the orignal req/response.
-Kaustubh.
 
kavitha rama
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, in sendRedirect, new request object is created and doesn't carry any of old requests where as forward is done by same request, it carries request object and client is not aware of it. Forward is faster than redirect but one disadvantage is that URL is not changed and also it works with in same web application.
 
Manish Malhotra
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think response.sendRedirect in jsp is of HttpServletResponse & <jsp:forward > is of RequestDipatcher's forward(request,response) & not
HttpServletResponse.forward().
So, both r having from differnt classes. And difference is same as u have versed.
with rgds,
manish
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!