I notice that, on Jetty (Servlet container), by default, if there is an error, the entire Stack backtrace is sent to the browser, which isn't so good for the live environment.
So I have created a little "servlet-error.html" file and included it in my web app and referenced it from the web.xml.
My web.xml looks like:
<web-app>
..
<error-page>
<error-code>500</error-code>
<location>/servlet-error.html</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/servlet-error.html</location>
</error-page>
</web-app>
The WAR file looks like:
servlet-error.html
WEB-INF/web.xml
...
When I don't have the <error-page>
section then I get the standard Jetty error (with backtrace), when I have it then I just get a white page in Firefox, and a standard browser error message in Chrome. There are no errors in the Jetty logs like "servlet-error.html could not be found".
I have tried changing the web.xml from /servlet-error.html
to /servlet-error-xxx.html
and there was no change (= white page, and no error in Jetty log). So I suspect it can't find by HTML file.
Additional information: The application is written in Wicket, the application is in Wicket "deployment mode", the exception causing the error is being thrown in the constructor of the Application (which seems to bypass Wicket's error handling and hiding of the exception backtrace in deployment mode?). The wicket application is being included via a <servlet>
not a <filter>
.
P.S. This Jetty is behind an Apache, so is this even the right way to handle this, or should I add something to the Apache config, i.e. "if Jetty returns != 200 then ignore what Jetty returns and instead display this error page..."
Edit: I have corrected the original reason for the error (i.e. the app now works without error) and now I can surf to http://mydomain.com/context-root/servlet-error.html, whereas before I would get the 500 error if I surf to that static HTML page. I see that I have in my web.xml:
<servlet-mapping>
<servlet-name>my-app</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I suspect that, when Jetty tries to execute the normal request, sees the error, then it tries to fetch the servlet-error.html
page, which it also fetches by using the web.xml
which falls again into trying to go to the application, which again generates the error.. And presumably to stop an infinite loop, it just displays a blank page to the browser, although something in the log would be nice!
But I'm still not sure what the right way to solve it is....
I added the following, but it didn't help.
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>