Tomcat 3.2.4 problem after response.sendRedirect(...)

Discussion in 'Java' started by Andreas, Feb 14, 2005.

  1. Andreas

    Andreas Guest

    Hi all,

    I am currently struggling with a Tomcat issue. My version of the Tomcat is
    3.2.4. When I send a redirect within the service method of my controller
    servlet and have a return statement after it I get a page cannot be found in
    the Internet Explorer. It isn't always occuring just ranomized. Any idea
    where the problem could be? I guess it is related to my Tomcat version
    3.2.4. When I add following code before calling return it seems to be
    working.

    response.sendRedirect(response.encodeRedirectURL("...."));

    try {
    Thread.sleep(1000);
    } catch (InterruptedException intExc) {
    ...
    }
    return;
    }

    Thanks a lot,
    Andreas
    Andreas, Feb 14, 2005
    #1
    1. Advertising

  2. wow, that's an old version. You should really get a new one.
    When you get page not found what page does it refer to? Is it the page
    you are redirecting to? That would sound strange..
    Andrea Desole, Feb 14, 2005
    #2
    1. Advertising

  3. Andreas

    Andreas Guest

    Yes, it is exactly the page I am redirecting to. I have also debugged the
    code several times and there was one interesting thing which I have
    observed. When I set a breakpoint after sending the redirect and before
    finishing the service method e.g. call return it is also working. I can see
    that the page is displayed in my browser while being in the breakpoint of
    the service method.

    Any clue how to solve it any workaround for it?

    By the way I am using this really old vesrion of Tomcat because of some
    internal reasons.
    Andreas, Feb 14, 2005
    #3
  4. Andreas wrote:
    > Yes, it is exactly the page I am redirecting to. I have also debugged the
    > code several times and there was one interesting thing which I have
    > observed. When I set a breakpoint after sending the redirect and before
    > finishing the service method e.g. call return it is also working. I can see
    > that the page is displayed in my browser while being in the breakpoint of
    > the service method.

    well, this is strange. Whether you wait or not it shouldn't make a
    difference, your destination url is always there. If the server sends a
    redirect to the browser, then the server doesn't have control anymore:
    the browser just asks for the new url.
    Are you sure that your destination url works? Maybe you have some
    threading issues that prevent the new page from being displayed? How
    about redirecting to a dummy page, like java.sun.com?

    >
    > Any clue how to solve it any workaround for it?

    well, I was thinking that there could be issues with how tomcat sends
    the response (although I have worked with older versions of Tomcat and
    never had this problem), and I was going to suggest to try to flush the
    buffer. But if the browser gets the redirect correctly then Tomcat is
    doing the job correctly.

    >
    > By the way I am using this really old vesrion of Tomcat because of some
    > internal reasons.

    I was hoping it was not depending on you :)
    Andrea Desole, Feb 14, 2005
    #4
  5. Andreas wrote:

    > Hi all,
    >
    > I am currently struggling with a Tomcat issue. My version of the Tomcat is
    > 3.2.4. When I send a redirect within the service method of my controller
    > servlet and have a return statement after it I get a page cannot be found in
    > the Internet Explorer. It isn't always occuring just ranomized. Any idea
    > where the problem could be? I guess it is related to my Tomcat version
    > 3.2.4. When I add following code before calling return it seems to be
    > working.
    >
    > response.sendRedirect(response.encodeRedirectURL("...."));
    >
    > try {
    > Thread.sleep(1000);
    > } catch (InterruptedException intExc) {
    > ...
    > }
    > return;
    > }


    It should not be necessary to insert a delay before returning. It may
    be that you are running into a bug in that decrepit version of Tomcat,
    in which case you may find reference to it in Tomcat's Bugzilla
    database. One alternative that occurred to me, however, is that your
    controller servlet may not be thread safe (as it needs to be). I
    haven't worked out an exact scenario for the behavior you described, but
    it is certainly likely to result in a request for the redirect target
    coming in before the thread in which the original request was processed
    finishes with that request.

    Wild guess: you're not trying to cache request objects or the
    corresponding response objects past the end of request processing, are
    you? That is absolutely not permitted and is known to in fact cause
    bugs to manifest in webapps that attempt to do it. (This is in fact a
    thread safety problem at its core.)

    --
    John Bollinger
    John C. Bollinger, Feb 14, 2005
    #5
  6. Andreas

    Andreas Guest

    Hello Andrea,

    I have to correct myself. It isn't the same URL. It is really a different
    one. I thought all the time that it is the same but it isn't.

    Do you have now any clue?

    Thanks a lot for your help,
    Andreas

    "Andrea Desole" <> wrote in message
    news:...
    > wow, that's an old version. You should really get a new one.
    > When you get page not found what page does it refer to? Is it the page
    > you are redirecting to? That would sound strange..
    Andreas, Feb 15, 2005
    #6
  7. Andreas wrote:
    > Hello Andrea,
    >
    > I have to correct myself. It isn't the same URL. It is really a different
    > one. I thought all the time that it is the same but it isn't.


    Interesting. And what url is it?

    >
    > Do you have now any clue?


    Well, the idea of flushing the response content might help. In that way
    the response is commited, including the redirect information. I also
    remember that, with older versions of Tomcat, some strange problems were
    occurring when mixing the servlet jars. Please check that your
    application doesn't have its own servlet.jar or j2ee.jar or anything
    like that. In one word, make sure that your application uses the J2EE
    classes that come with Tomcat.
    Also, you might want to check out what John Bollinger said.
    An idea might also be to look at places in your code where redirect
    works. If there aren't any, try to build a very simple application with
    just one redirect, and see what happens. And, just to check if it's
    tomcat, maybe you can try your code with a newer version of tomcat.
    By the way, did you try to redirect to a simple external page? A page
    that is not in your application and that works? What happens?
    Andrea Desole, Feb 15, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. carlisle411
    Replies:
    4
    Views:
    12,272
    John C. Bollinger
    Feb 28, 2005
  2. Jeano
    Replies:
    5
    Views:
    7,231
    Orilg
    Oct 13, 2010
  3. ohaya
    Replies:
    0
    Views:
    4,078
    ohaya
    Jun 30, 2005
  4. Replies:
    1
    Views:
    805
    chris brat
    Jun 2, 2006
  5. Replies:
    0
    Views:
    1,190
Loading...

Share This Page