There's a lot of processing after the sendRedirect(). The sendRedirect() is
contained in Grails platform code and I confess that I don't fully
understand the motivation behind all of the processing. The sendRedirect()
has occurred after an application defined exception has been thrown. A
Spring exception resolver has forwarded the request after the exception has
been thrown. sendRedirect() occurs after the forward.

Here is the code that sends the redirect. It is Grails code except that I
added some of the verbose logging statements and the "catch (Exception ex)"
just to be sure I wasn't missing an exception:

    private Object redirectResponse(String actualUri, HttpServletResponse
response) {
        if(LOG.isDebugEnabled()) {
            LOG.debug("Dynamic method [redirect] forwarding request to
["+actualUri +"]");
        }

        try {

            if(LOG.isDebugEnabled()) {
                LOG.debug("Executing redirect with response
["+response+"]");
            }
            String redirectUrl = response.encodeRedirectURL(actualUri);
            response.sendRedirect(redirectUrl);

        } catch (IOException e) {
            throw new ControllerExecutionException("Error redirecting
request for url ["+actualUri +"]: " + e.getMessage(),e);
        } catch (Exception ex) {
            LOG.error("redirectResponse: caught Exception=" + ex);
            throw new ControllerExecutionException("Error redirecting
request for url [" + actualUri + "]: " + ex.getMessage(), ex);
        }
        return null;
    }


I'm certain that the redirect is never sent to the browser. I've been using
Firebug and HttpWatch to monitor each request and response. When I execute
this code on Jetty I do see the redirect sent to the browser.

I took a look at the Error Handling sections of the Servlet spec and it
wasn't clear to me if perhaps the redirect is not permitted after an
exception has been thrown.

Any suggestions would be appreciated.


Qiao Jin wrote:
> 
> What's after the sendRedirect() call in your code? And what's in the
> final?
> Can you post a simple code sample that would demonstrate the problem?
> 
> On Mon, Feb 16, 2009 at 5:55 PM, Brad Whitaker <dbw...@yahoo.com> wrote:
> 
>>
>> I'm having a problem with Tomcat 6.0.18 that I don't understand. I'm
>> invoking
>> HttpServletResponse.sendRedirect() but no redirect is being sent to the
>> browser. Is there a valid reason why this might occur, or is this likley
>> a
>> bug in Tomcat?
>>
>> My code has thrown an exception prior to invoking the redirect but I
>> can't
>> find anything in the Servlet spec that would indicate this is a problem.
>> The
>> HttpServletResponse.sendRedirect() is within a try/catch block and no
>> exception is being thrown in response to sendRedirect(). My app is built
>> on
>> Grails (which in turn is built on top of Spring) and I don't fully
>> understand the exception resolution process used by my frameworks, but I
>> have verified that sendRedirect() is being executed and not throwing an
>> exception. This same code is working as desired when executed on Jetty
>> (i.e.
>> the desired redirect is received by the browser) but when executed in
>> Tomcat
>> I see the default Tomcat error page displayed rather than the redirect.
>>
>> Any advice or suggestions would be appreciated.
>> --
>> View this message in context:
>> http://www.nabble.com/HttpServletResponse.sendRedirect%28%29-not-working--tp22049004p22049004.html
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/HttpServletResponse.sendRedirect%28%29-not-working--tp22049004p22051065.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to