I'm using Jetty as my servlet container. If an exception is thrown in one of my servlets the browser will display an HTTP ERROR 500 with the exception message and a stack trace.
For security reasons I need to hide the stack trace. Is there a way to configure this generally? Or do I need to trap all Throwables in my Servlet?
Thanks
Get a Stack Trace Using the Thread Class We can obtain a stack trace from a thread by calling the getStackTrace() method on the Thread instance. It returns an array of StackTraceElement, from which details about stack frames of the thread can be found.
A stack trace shows the call stack (sets of active stack frames) and provides information on the methods that your code called. Usually, a stack trace is shown when an Exception is not handled correctly in code. (An exception is what a runtime environment uses to tell you that there's an error in your code.)
In computing, a stack trace (also called stack backtrace or stack traceback) is a report of the active stack frames at a certain point in time during the execution of a program.
You can set up a custom error page in your web.xml file, with something like this:
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/jsps/errors/error.jsp</location>
</error-page>
Then in your error.jsp, display a custom message and don't show the stacktrace.
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