Here is what is happening.
response.sendRedirect() is setting an error header, I don't remember the
error number, maybe 203? The header is the a temporary URL redirect message
that contains the URL to redirect to. Once the header is written out to the
browser, the redirect takes place. Until the response is written out to the
client, the redirect is just part of the uncommitted response header.
The real issue here is to ask, "when is the header written out to the
client?" The answer is the same as any other JSP, when the page is flushed.
So, if you continue to execute your jsp after returning from the
response.sendRedirect() method, then the execution of the servlet will
continue.
The easiest way to make sure your response is commited to the client is to
do a return. This will guarantee a flush of the current response buffer.
So, your code should look like this with a return after the sendRedirect:
<%
...
if ( flag )
{
response.sendRedirect( "http://somedomain.com/someurl.jsp?q=somequery"
);
return;
}
...
%>
-----Original Message-----
From: John Doe [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 28, 2000 12:36 PM
To: [EMAIL PROTECTED]
Subject: Re: response.redirect
Can anyone please refer me to some concrete documentation on this. I would
really like to know if this is true: is there another thread created which
does the redirection code, while the current thread continues executing the
code on the current page?
thank you
rostom
--- "Mauro Gagni (EMS)" <[EMAIL PROTECTED]> wrote:
> Hi,
> I had the same problem and that is the way it work, it compute the code
> until the end of the page.
> I noticed that it actually creates a new thread for the redirection, while
> the old one keeps executing until it eventually dies at the end of the
page.
>
> hope it did help,
> mauro
>
> > -----Original Message-----
> > From: A mailing list about Java Server Pages specification and reference
> > [mailto:[EMAIL PROTECTED]]On Behalf Of John Doe
> > Sent: 28 June 2000 02:40
> > To: [EMAIL PROTECTED]
> > Subject: response.redirect
> >
> >
> > Hello,
> > Can someone give a detailed explanation of how
> > response.redirect() works. I
> > looked at the API and its not very detailed.
> >
> > The reason for this is that it seems that if I have html or java
> > code AFTER a
> > redirect on a JSP page, that code still gets executed. This is not the
> > behavior i want. With a forward I know that all execution stops
> > and a forward
> > takes place. Is this not the case with a redirect??
> >
> > thanks in advance.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets