I have created a 404 page and am currently testing it with a simple page request that I know does not exist. This code will show the error page I have made (aka the result I want).
<!-- CONFIGURATION FOR ERROR PAGES -->
<error-page>
<!--<exception-type>java.lang.Throwable</exception-type>-->
<error-code>404</error-code>
<location>/videoNotFound</location>
</error-page>
However, this code will show the apache tomcat default error page
<!-- CONFIGURATION FOR ERROR PAGES -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<!--<error-code>404</error-code>-->
<location>/videoNotFound</location>
</error-page>
Any ideas why this is occurring, or what I could try to maybe fix this problem? Even though option 1 works, I prefer option 2 because I do not want to have a specific error page for each exception type.
404andjava.lang.Throwableare two very different error conditions triggered under different circumstances. the404like you’ve tested yourself is triggered by requesting a non-existent/unreachable resource and thejava.lang.Throwableis an error condition that occurs as a result of an internal server/programming error, and it’s represented by the http status code500. This condition, you cannot simulate by simply accessing an unreachable resource; the nature of4xxstatus codes generally is that they’re thrown before the request even gets to your web application while the500series error codes are mostly web app generated. The only way to test for this is to throw an instance of throwableExceptionorErrorwithin your web application code.In the end, you will have to have two separate
error-pagedefinitions, one for container-related errors (essentially the4xxstatus codes) and another for the500/throwabletype error conditions