I'd like to direct all errors to my Errorsevlet without specifying all the codes explicitly. Is there any way to do like that?
<error-page>
<error-code>400</error-code>
<location>/servlet/com.abc.servlet.ErrorServlet</location>
</error-page>
**And after reaching the ErrorServlet how can i get the stack trace of the error in the servlet. So that i can email the details when one error occurs. **
If you can upgrade, since Servlet 3.0 it's possible to have a generic error page for all errors, even those not caused by an exception (e.g. 404, 401, etc). Just omit the <error-code>
or <exception-type>
altogether so that you only have a <location>
.
<error-page>
<location>/errorServlet</location>
</error-page>
Note that I replaced the URL to avoid the use of Tomcat's builtin and deprecated InvokerServlet
.
You will need to specify all the desired codes explicitly, a wildcard mechanism is not supported. There are not that many codes, here is a full list.
To print out the stacktrace (e.g. in a comment, for debugging purposes), you could do something like this:
<%@ page isErrorPage="true" import="java.io.*"%>
<body>
<p>Sorry, there was an error.</p>
<!-- The full stacktrace follows:-->
<!--
<%
if (exception != null) {
exception.printStackTrace(new PrintWriter(out));
}
%>
-->
</body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With