I am implementing a custom 404 handler in JSP - AEM, CQ. The file lives in apps/sling/servlet/errorhandler/404.jsp
I am intercepting the request for Not Found and forwarding using RequestDispatcher class.
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling"%>
<sling:defineObjects />
<%
// 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);
}
%>
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.
How can I return a 404?
Pagesupertype), as it's knitted into thelibsdirectory. I'd suggest using something like the ACS Commons Error Page Handler plugin to take the pain out of it - anotherdave