title: Encoding issue in httpheader result in struts 2
body: <p>I am sending in an struts 2 application the message of a custom error in the heading. I've done it by adding to the struts.xml file a global result like:</p>
  
  <pre><code>&lt;global-results&gt;
      &lt;result name="badDataError" type="httpheader"&gt;
         &lt;param name="status"&gt;500&lt;/param&gt;
         &lt;param name="headers.errorMessage"&gt;${exception.message}&lt;/param&gt;
      &lt;/result&gt;
  &lt;/global-results&gt;
  
  &lt;global-exception-mappings&gt;
      &lt;exception-mapping result="badDataError" exception="mypackage.BadDataException" /&gt;
  &lt;/global-exception-mappings&gt;
  </code></pre>
  
  <p>so when I throw an exception like </p>
  
  <pre><code>throw new BadDataException("my error message");
  </code></pre>
  
  <p>then that message is included in the header of the file so it can be read in a json as an error:</p>
  
  <pre><code>$.ajax(
      { 
          url: ...,
          type: "POST",
          data: ...,
          success: function(data, textStatus) {
              alert("save works");
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
              var errorMessage = XMLHttpRequest.getResponseHeader('errorMessage'); 
              var message = "There has been an error";
              if (errorMessage != null){
                  message = message + ':&lt;br/&gt;'+errorMessage;
              }
              alert(message);
          },
          dataType: "json"
      }
  );    
  </code></pre>
  
  <p>This works, but whenever I send a message with any special character (e.g. á é ñ ...) it's not shown correctly neither in the alert or by displaying the variable with console.log(), though if I use firebug there the message is shown correctly, as if it wasn't using the correct encoding in javascript.</p>
  
  <p>I've tried to set in the ajax call</p>
  
  <pre><code>contenType: 'application/x-www-form-urlencoded; charset=UTF-8'
  or
  contenType: 'application/x-www-form-urlencoded; charset=ISO-8859-1'
  </code></pre>
  
  <p>but without any success.</p>
  
  <p>How can I know which encoding it's being used for the error message and the header and being able to choose a different one for it?</p>
  
  <p>Thanks.</p>