title: Send 404 using request dispatcher JSP
body: <p>I am implementing a custom 404 handler in JSP - AEM, CQ.
  The file lives in apps/sling/servlet/errorhandler/404.jsp</p>
  
  <p>I am intercepting the request for Not Found and forwarding using RequestDispatcher class.</p>
  
  <pre><code>&lt;%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling"%&gt;
  &lt;sling:defineObjects /&gt;
  &lt;%
      // setting response code as 404
      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
  response.setStatus(404);
  System.out.println(response.getStatus());
          try {
              RequestDispatcher rd = request.getRequestDispatcher("/error-page.html");
  
              rd.forward(request, response);
  
  
          } catch (Exception e) {
              RequestDispatcher rd = request.getRequestDispatcher("/error-page.html");
              rd.forward(request, response);
  
          }
  
  %&gt;
  </code></pre>
  
  <p>The above code gets the content of error-page.html keeping the URL same, but the response code sent back is not 404. It is 200 instead.</p>
  
  <p>How can I return a 404?</p>