title: Handling java Exception after Spring Framework has started writing to client
body: <p>In my web app I am encountering a scenario where an exception is occurring in one of my views. Since the web server has already started writing data to the client, it encounters the Exceptions and goes to the default error pages I have defined in web.xml. </p>
  
  <p>I have tried things like <code>response.reset();</code> and <code>response.resetBuffer();</code> but to no avail these haven't changed the behavior. The content being sent to the client looks something like this.</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
  
      &lt;!-- Partial content delivered --&gt;
  
      &lt;!-- EXCEPTION OCCURS, error.jsp is sent --&gt;
  
  &lt;html&gt;
    &lt;head&gt;...&lt;/head&gt;
    &lt;body&gt;
      &lt;!-- Stack trace --&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So as you can see the HTML is getting all mangled since the exception happens after some of the data has been sent to the client and nothing renders, not even error.jsp. So to be clear my question is. What is the best practice to avoid this happening? and How can I redirect a user of my app after they have recieved some of the content?</p>