Justin, I followed the instructions I outlined in the link above. Once I had the 404.jsp that POINTS to the default.jsp (that the article explains to do), I modified my default.jsp to FORWARD (not redirect) to a normal content page CALLED 404. The reason I did this was to keep the dynamic links and header information coming from the main site, to the 404 page. I did this because every time I tried to do an include on the default.jsp, it would fail, thus the forward (to keep the response code) to the new page. Any ideas?
There should be no default.jsp, just a 404.jsp. I'm confused when you say "Once I had the 404.jsp that POINTS to the default.jsp". Can you explain how you did this (exact steps)?
Anyway, your content page that you forward to should have the following:
I'd recommend creating a new page component that contains this code.
When you go through the documentation on the link I sent, it specifically says:
In the repository, copy the default script(s):
- from /libs/sling/servlet/errorhandler/
- to /apps/sling/servlet/errorhandler/
So, I took the default scripts in the original location, which included BOTH 404.jsp and default.jsp. So, if you try to go through the example, you will see that I have done what is outlined, and the error page works if I just allow it to go here, but then I'm missing all of the dynamic content from my site, which is why I'm forwarding, along with doing the 'response.setStatus(404);' before forwarding. Forwarding SHOULD keep the status. Does that make more sense?
Okay, looks like default.jsp exists in CQ5.5 but not in CQ5.4. Looks like default.jsp is a generic error handler if a specific one doesn't exist.
What I think is probably going on in your case is something else is resetting the status to 200 as part of the resource resolution process for the new page. What you probably should do is set the status in the new script you are redirecting to rather than trying to do it in the 404.jsp. This makes sense anyway because what you are doing with the forward is delegating the handling of the response to some other servlet.
I don't know why I didn't think about that... I did that, and it works. So now, whenever someone goes to an error page, as long as that error page is on the 'error page template' I've created, the template will take the title of the page, and set the response status to that. So if the error page is 404.html, it will be a 404 error. PERFECT! Thanks!