hi If I write something to the outputstream after calling sendError, what will happen ? The SCWCD Exam Study Kit says that this will cause IllegalStateException to be throws. But I have read somewhere else that the error would be just ignored. Which is correct ? Thanks Seema
Sun Certified Java Programmer<br />Sun Certified Web Component Developer<br />Sun Certified Business Component Developer
The specification says "If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to." Which means, after this method is called, if anything is written to response, will be ignored (nowhere it is mentioned that IllegalStateException will be thrown) HTH -Varun
Joined: Sep 30, 2001
hi Thanks for the info. Actually, I got this info from the SCWCD Study Kit by Hanumant Deshmukh. In the answer to question no: 2 of Chapter 7, it says " When the sendError() method is called, the response is assumed to be committed. If you write anything to the response after it is committed, IllegalStateException is thrown." So they have given this as the correct answer to that question. Is this is a mistake in the book ? Thanks Seema
YES IT'S A MISTAKE IMPORTANT concept( IS the response committed BEFORE CALLING sendError()or not?)
The answer is NO,(unless the buffer is full and flush() is called automatically) OR YOU FLUSH THE BUFFER EXPLICITLY)no exception will be thrown .As far as the statement AFTER calling sendError() is concerned ,if you write to the response then the data will be "SIMPLY IGNORED" and no exception is thrown. "This method will have the side effect of committing the response ,if it has not already been committed and,TERMINATING it. "for example if the buffer is half full,and you call sendEror() it will commit the response and TERMINATE it(SIDE EFFECT). Once again don't bother about the data written to the response after sendError is called,it's simply ignored.The exception is thrown only if the response is committed before this method is called.