Meaningless Drivel is fun!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes sendError() - commited Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "sendError() - commited" Watch "sendError() - commited" New topic
Author

sendError() - commited

Renata fonseca
Ranch Hand

Joined: Mar 15, 2002
Posts: 48
the SCWCD book says that sendError() must be called before commiting the response.
But..

I tested it but it didn't throw any exception! WHY?
Raji Ram
Ranch Hand

Joined: Aug 22, 2002
Posts: 46
Originally posted by Renata fonseca:
the SCWCD book says that sendError() must be called before commiting the response.
But..

I tested it but it didn't throw any exception! WHY?


Hi Renata,
out.println(1); does not commit the response.
You have to write a code to flush.

Hope it is clear.
Good luck!!


Regards,<br />Raji.
Renata fonseca
Ranch Hand

Joined: Mar 15, 2002
Posts: 48
Originally posted by Raji Ram:

I tested it but it didn't throw any exception! WHY?<hr></blockquote>

Hi Renata,
out.println(1); does not commit the response.
You have to write a code to flush.

Hope it is clear.
Good luck!![/QB]


I tried it... But it didn't work yet. No exception was threw... and print "1" in the browser output.
Sri Ram
Ranch Hand

Joined: Sep 08, 2002
Posts: 48
I posted this question to MR.Hanumant Deshmukh, see below for his reply...
The idea is if the client receives any data other than the redirect header from the server, you cannot redirect it to another location. Now, servers usually buffer the data that you write using out.print(). So if you print a lot of data to out, it will be sent to sent to the client as soon as the buffer is full. You may not even need out.flush() to "commit" the response. In some cases, if you write very little data, even out.flush() may not immediately send the data (usually it does though). It is implementation dependent.
So, you should not write to the output if you want to redirect the client.
BTW, as per the API, res.sendRedirect() commits the response. I.e. it probably sets a committed flag (no matter whether any of the output has been sent to the client or not).
===================
I'm just a programmer!
Raji Ram
Ranch Hand

Joined: Aug 22, 2002
Posts: 46
Thanks Vanniarajan.
[ February 18, 2003: Message edited by: Raji Ram ]
Renata fonseca
Ranch Hand

Joined: Mar 15, 2002
Posts: 48
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sendError() - commited