<p>(See related question: <a href="https://stackoverflow.com/questions/162917/how-do-i-report-an-error-midway-through-a-chunked-http-repsonse-without-closing">How do I report an error midway through a chunked http repsonse without closing the connection?</a>)</p>

<p>In my case, the #1 desire is for the browser to display an error message.  No matter how uninformative.</p>

<p>Closing the ServletResponse outputStream obviously doesn't work.  Neither does throwing an exception, even if I don't close first (tested on Tomcat 6.0.16).  I think that what I want is either a RST packet, FIN in the middle of a chunk, or badly formed chunk headers.</p>

<p>After that I can worry about how various browsers respond.</p>

<p>Edited for clarification: This is for a file download, perhaps several gigabytes of binary data.  I can't make certain that all of the data can be successfully read or decrypted before I have to start sending some of it.</p>

I think you're going about it the wrong way. It seems like it would be simpler to not actually start sending the data until you're sure if will be a success or a failure. That way you can send an error message at the start if needed, instead of sending partial data that's not valid.
If you really must, you might be able to wrangle something up with JavaScript. When you get to the error, output something like this before closing the connection:
```
```
<script type="text/javascript"> alert("Processing failed!"); </script>
```
```
You might want to expand on the script, but you get the general idea. This is assuming that what's being sent back to the browser is a HTML page, you didn't specify that in the question.