First off, let me say that I am not a Java programmer or very familiar with Tomcat so please bear with me :) I am working with a SaaS application running on Apache Tomcat 5.0.9. I do not have access to the server configuration files nor can I add .jsp files.
The situation I am in is I have a script that is running in a Mozilla Rhino environment and I have access to the following two objects:
org.apache.coyote.tomcat5.CoyoteRequestFacade org.apache.coyote.tomcat5.CoyoteResponseFacade
I need to set the status to SC_NOT_FOUND (404) and provide a custom message. The problem is, no matter what I do, if the status is 404, I get an "ugly" 404 error message as set by the vendor. I have tried using "sendError", "setStatus", I've tried getting the dispatcher and redirecting to another page while also setting the status to 404, I've tried a wrapper but not sure what I'm doing, and I've seen information about filters but do not know how to apply that in this situation or even if that is the right approach.
Again, it seems that as soon as the 404 is set, the web server serves up it's own page. I'm assuming this is an "error page declaration" that I cannot override. I have read through this question How to get the message in a custom error page (Tomcat)? (and many others) but I do not understand this enough to translate the information to my particular situation.
So, is it possible to "override" an error page declaration programmatically? Or, how can I return a 404 error and a custom error page given the limitations of the environment I am in? I would settle, at this point, for just plain text - doesn't have to be fancy. I just need some way to use the 404 status and display a "user friendly" message.
Any help would be greatly appreciated!
P.S. I should mention that the reason for this approach is that the page in question will be consumed (potentially) by both a search engine and humans. I need the 404 so that the search engine removes the page from its cache and I need the "pretty" message to tell the human vistor what steps they need to take due to the no longer available page.