This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:foward vs response.sendRedirect

 
Jo Liang
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
What is the difference between jsp:foward and HttpServletResponse.sendRedirect??
Here is some API regarding to each technique.
<jsp:forward />:
This method is used to re-direct, or "forward" the current ServletRequest and ServletResponse to another active component in the application.

HttpServletResponse.sendRecirect:
Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs.
But does that really make difference when coding the application?
Thank you.
- Jo
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the main diffrence is that the forward one does the redirecting at the server side while the sendRedirect one redirects to a new URL at the client's side ( the browser).
the sendRedirect one also loses the request and response data you may have put in (like forms attributes etc) while the forward one doesnt.
 
sanj singh
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jo,
One big advantage of sendRedirect() is that you can send your request to another Context.
regards
sanj
 
Geeta Gune
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
the main difference between jsp forward and redirect is that the code execution stops after u use the jsp forward while in redirect the code is executed till the end.
For ex. try the foll code in a jsp file with both redirect and forward:
Ex:Checking.jsp

here ..only "i=5" shall be printed out to the console.it means that the code execution has stopped after forward.
but in redirect the code execution does not stop..so it will print both the statements.
so according to me its better to use forward than redirect.
Hope this helps.
bye
geeta
 
Amir Kamran
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
jsp:forward is used to trasfer control to some other resource a static or a dynamic page. It is totally on server even the url bar of the client is not change. and also by passing the reference of request and response objects u can use them in the forwarding page.
In case of sendRedirect(), first a error code is send to the client and the connection of http is break. Then a new request is send to the server. This causes a new request and response objects. U can not send attributes with request.
Another difference is that in sendRedirect() the connection is made more than once b/w server and client the process is slow as compered to forward which is totally on server.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic