Well, it's not a given that the redirect will occur if you use some logic. Redirect is one of those tools that should be used sparingly anyway. By putting the response near the top, I mean that you need to avoid outputting much data before issuing the redirect. Not as easy as it sounds, since even line breaks between tags puts out content. I would assume that setting the buffer cache to a large amount could have a detrimental effect on performance.
V. Jagadesh Lee wrote:
Again, if we could redirect at the beginning of the page then why redirect at all. Usually the redirection happens based on evaluation of certain condition. The following code works (even without the buffer but I added it just in case).
<%@ taglib uri="http://jakarta.apache.org/taglibs/response-1.0" prefix="response" %> <%@ page buffer="64k"%>
<H1> hello How are you?</H1> <% //some condition evaluation response.reset(); out.close(); response.sendRedirect("jsp2.jsp"); %> <response:sendRedirect> <response:encodeRedirectUrl>"jsp2.jsp"</response:encodeRedirectUrl> </response:sendRedirect>
best wishes Lee
-----Original Message----- From: A mailing list for discussion about Sun Microsystem's Java Servlet API Technology. [mailto:[EMAIL PROTECTED] On Behalf Of Eric Noriega Sent: Monday, June 23, 2003 11:40 PM To: [EMAIL PROTECTED] Subject: Re: Redirecting the browser to another page
How do you close the output stream before redirecting? The whole point is that the redirect has to happen before the commit. Otherwise the response headers have been sent, and so the redirect response code cannot be sent.
Just put the tag at the start of the jsp file.
<[EMAIL PROTECTED] ... %><%@ taglib uri="http://jakarta.apache.org/taglibs/response-1.0" prefix="response" %><response:sendRedirect><response:encodeRedirectUrl>"http://somepage.js p"</response:encodeRedire ctUrl></response:sendRedirect>
etc . .
V. Jagadesh Lee wrote:
ServletUsually before redirecting response or before forwarding request it is best not open the output stream. If the output stream is committed then you should flush or close the output stream before redirecting. Some times the errors associated with redirecting and forwarding is due to the web container implementation. In such case you should contact the vendor.
Lee
-----Original Message----- From: A mailing list for discussion about Sun Microsystem's Java
API Technology. [mailto:[EMAIL PROTECTED] On Behalf OfAsad
eHabib Sent: Thursday, June 19, 2003 8:33 PM To: [EMAIL PROTECTED] Subject: Redirecting the browser to another page
Does anyone know how to do this successfully? I am using the "response" Jakarta Taglib but I keep getting the following error:
javax.servlet.ServletException: Response sendRedirect tag could not return the redirect: Response has already been committed
I am using the following code:
<%@ taglib uri="http://jakarta.apache.org/taglibs/response-1.0" prefix="response" %>
<response:sendRedirect>
<response:encodeRedirectUrl>"http://somepage.jsp"</response:encodeRedir
clientctUrl> </response:sendRedirect>
I don't quite understand how the server has committed a request to the client and if it has, how can I uncommit that request so that the
can be redirected successfully?_
Any help would be greatly appeciated. Thanks.
-Asad
_______________________________________________________________________
_______ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
_______________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in thebody
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
________________________________________________________________________ ___ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html