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

A

Andreas

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
 
A

Andrea Desole

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..
 
A

Andreas

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.
 
A

Andrea Desole

Andreas said:
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 :)
 
J

John C. Bollinger

Andreas said:
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.)
 
A

Andreas

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
 
A

Andrea Desole

Andreas said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top