title: Header not getting set for a HttpServletResponse
body: <p>Hey I am trying to implement a servlet where in case of an exception, I add a header to the response:</p>
  
  <pre><code>    catch (Exception e) {
                  response.addHeader("ErrorCode", e.getErrorMessage());
                  response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                          e.getErrorMessage());
              }
  </code></pre>
  
  <p>and on the client side I store all the headers in an array:</p>
  
  <pre><code>    Header[] header=response.getAllHeaders();
  
      if(header.length&gt;0)
      {
       errorMessage = header[0].getValue();
       //do this for all the six elements in the header[] array
  
      }
  </code></pre>
  
  <p>But in the response I cannot see the header with name <code>ErrorCode</code>. While debugging I can see that my servlet is throwing an exception. But on the client side I cannot see the header name/value. What can be the reson behind this? Should i use <code>setHeader()</code> instead of <code>addHeader()</code>? Does it matter in this case?</p>