Bansal Simply put, when you send a redirect, the server tells the browser to go to another resource. In a forward it is invisible to the client and the browser, the new resource is returned as if it had come from the originally requested one. A redirect would be if the user tried to access something that they had to log in for , you could redirect them to a login page. While a forward would be if you need to examine the request to determine what to do with it then forward it to another resoure for processing. The client doesn't neccesarily need to know that you've done that, they just want the results. hope that helps clear it up a little.
Hi, I tried both resonse.sendRedirect() and jsp:forward tag. I come to know that using sendRedirect() previous parameters are not passed to redirected page and the URL changes. with JSP forward tag previous parameters are passed to the forwarded page but URL do not change. I m using tomcat 4 but on actually when I applied response.sendRidirect() i m getting very bad output. output from previous page and redirected page. where is the problem thanx and regards Bansal
Sunil you may need to use one of response method calls to clear the buffer before sending it to the browser in case of a redirect. The problem is that you have already written to the before before redirecting the response Use one of response.flushBuffer() or response.resetBuffer() based on whether you want to reset the Headers or not.
in servlets you have to explicitly write output back to the browser using: out.println("some stuff") comments. In JSP, the following will return a return to the client: <%@ page language="java"%> <% %> why? well, despite the fact that there doesnt seem to be any HTML, the line return between the first line and the rest is enough to send the line return that seperates them. If you want to guarantee no content is returned and you wont learn how to use the buffers then you will need to rewrite your jsps to: <%@ page language="java"%><% %> so that there is absolutely nothing the compiler could consider as requiring sending back to the browser.
chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>