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
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.
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
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.