title: How to properly send an HTTP message to the client
body: <p>I'm working on a RESTful web service in Java.  I need a good way to send error messages to the client if something's wrong.</p>
  <p>According to the <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletResponse.html#setStatus(int,%20java.lang.String)" rel="nofollow noreferrer">Javadoc</a>, <code>HttpServletResponse.setStatus(int status, String message)</code> is deprecated <em>&quot;due to ambiguous meaning of the message parameter.&quot;</em></p>
  <p>Is there a preferred way to set the status message or &quot;<a href="https://www.rfc-editor.org/rfc/rfc2616#section-6.1.1" rel="nofollow noreferrer">reason phrase</a>&quot; of the response?  The <code>sendError(int, String)</code> method doesn't do it.</p>
  <p><strong>Edit</strong>: To clarify, I want to modify the HTTP status line, i.e. <code>&quot;HTTP/1.1 404 Not Found&quot;</code>, not the body content.  Specifically, I'd like to send responses like <code>&quot;HTTP/1.1 400 Missing customerNumber parameter&quot;</code>.</p>
  <p>Or I want to modify the HTTP status line to say something like <a href="https://datatracker.ietf.org/doc/html/rfc3229" rel="nofollow noreferrer"><code>227 IM Used</code></a> - in other words: an <em>HTTP Status Description</em> different from what the web-server would know to send.</p>