title: Tomcat Restful API 404
body: <p>GET api/users/1</p>
  
  <p>Here's the situation:
  if user 1 does not exist, respond a 404 http status code and a json message.
  The json message would like this:</p>
  
  <pre><code>{
    "message": "Resouces `api/users/1` does not exist"
    "error_code": 1000
  }
  </code></pre>
  
  <p>And here's the code:</p>
  
  <pre><code>if(user == null) {
          Map&lt;String, Object&gt; error = new HashMap&lt;String, Object&gt;();
          error.put("message", "Resource `api/users/" + id + "` does not exist!");
          error.put("error_code", 1000);
          return new ResponseEntity&lt;Object&gt;(error, HttpStatus.NOT_FOUND);
      }
      return new ResponseEntity&lt;Object&gt;(user, HttpStatus.OK);
  </code></pre>
  
  <p>But tomcat returns a default error page without the response body:
  <img src="https://i.stack.imgur.com/x2MsQ.jpg" alt="enter image description here"></p>
  
  <p>What should I do, if I want a page like below:</p>
  
  <p><img src="https://i.stack.imgur.com/A6fhj.jpg" alt="enter image description here"></p>