About committed response and stuff...

I have a servlet that acts strange and I don't know what might be the cause. I've simplified it to be easily understandable. I have a doPost that does the following:

This is how methodA looks like:

This is how methodB looks like:

If IOException is thrown in methodA at line #2, methodB() will be executed. So far so good. After the execution of methodB() nothing happens. I checked the committed ststus before calling methodB() and after and the values look normal (false and true). What happened with my forward? What is wrong in this picture? Can you guys give me an idea? Thanks in advance, Adrian [ November 28, 2002: Message edited by: Adrian Muscalu ]

You need to reorganise the 'do stuff here that causes an IOException', so that it has as little a chance of failing as possible. If you have a block that outputs to the client, as soon as the output buffer is full (usually 8k) the response gets sent and is committed. You can't forward somewhere else at this point. The Model-View-Controller helps a lot. Since all of the processing that is likely to fail is managed by the model and happens before the view starts, you always have the option of continuing or not. Dave

Adrian Muscalu
Ranch Hand

Joined: May 08, 2000
Posts: 73

posted Nov 29, 2002 07:56:00

0

Originally posted by David O'Meara: You need to reorganise the 'do stuff here that causes an IOException', so that it has as little a chance of failing as possible. If you have a block that outputs to the client, as soon as the output buffer is full (usually 8k) the response gets sent and is committed. You can't forward somewhere else at this point. The Model-View-Controller helps a lot. Since all of the processing that is likely to fail is managed by the model and happens before the view starts, you always have the option of continuing or not. Dave

You are correct, my problems started the moment line#2 throwed an exception. I still don't understand how. Correct. My request contains an uploaded file. If the size of the file is bigger than the value accepted by the MultipartParser constructor (O'Reilly) it throws an IOException. If I could only check the size of the file before the constructor... I assume that when I try to forward using RequestDispatcher, the uploaded file will still "travel" back to the client, am I right? I could really use a good book on MVC, with some practical example. Can you reccomend one? Thank you, Adrian [ November 29, 2002: Message edited by: Adrian Muscalu ] [ November 29, 2002: Message edited by: Adrian Muscalu ]