title: How to access HTTP response text in Tomcat error page
body: <p>I am using Tomcat 6 (but the same should apply to Tomcat 7). Let's say my <code>web.xml</code> contains this definition:</p>
  
  <pre><code>&lt;error-page&gt;
      &lt;error-code&gt;401&lt;/error-code&gt;
      &lt;location&gt;/Handle401Error.jsp&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>Suppose I now return HTTP 401 from some other servlet/JSP:</p>
  
  <pre><code>httpResponse.sendError(SC_UNAUTHORIZED, "This is a message");
  </code></pre>
  
  <p>How can I access the HTTP response text ("This is a message") in <code>Handle401Error.jsp</code>? The way Tomcat does this, when it shows an error page like this</p>
  
  <p><img src="https://i.stack.imgur.com/HZ1l2.png" alt="Tomcat error page"></p>
  
  <p>is by using a <code>Valve</code> (<code>ErrorReportValve</code>). Do I need to write a <code>Valve</code> as well?</p>
  
  <p>Edit: the accepted answer below is exactly what I have been looking for, and the assumed duplicate of this question does not mention the same solution.</p>