Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes About committed response and stuff... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "About committed response and stuff..." Watch "About committed response and stuff..." New topic
Author

About committed response and stuff...

Adrian Muscalu
Ranch Hand

Joined: May 08, 2000
Posts: 73
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 ]

SCJP2, SCWCD
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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
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 ]
Adrian Muscalu
Ranch Hand

Joined: May 08, 2000
Posts: 73
The problem has been solved. Apparently there was a bug that Paul Wetzel explained long time ago.
Here is the link:
http://www.coderanch.com/t/347482/Servlets/java/com-oreilly-servlet-MultipartRequest-weirdness
Adrian
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
Paul Wetzel's message is from september-2000 and the last version of the com.oreilly.servlet package is dated Nov-5 2002.
Is the bug still there?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About committed response and stuff...
 
Similar Threads
Synchronization on Threads in Java
try..catch block
objects and references
setRollbackOnly() related question
Certification Study Guide by Simon Roberts Philip Heller Micheal Ernst