tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brad Whitaker <>
Subject Re: HttpServletResponse.sendRedirect() not working?
Date Tue, 17 Feb 2009 05:32:37 GMT

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
            String redirectUrl = response.encodeRedirectURL(actualUri);

        } 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 <> 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:

View this message in context:
Sent from the Tomcat - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message