First you tell the web-server that you want to us a custom error page by specifying it in your web.xml:
web.xml:
<web-app>
    <!-- Any unhandled (i.e. Throwable) errors, display the page ysod.jsp (rather than the built-in default -->
    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/ysod.jsp</location>
    </error-page>
</web-app>
And then you create a new Yellow Screen of Death JSP file:
ysod.jsp
<!DOCTYPE html>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.StringWriter"%>
<%@page import="java.io.StringWriter"%>
<%@page isErrorPage="true" %>
<%!
    public String htmlEncode(String s)
    {
        //Java does not have any htmlEncode or escapeHtml (https://stackoverflow.com/a/1400705/12597)
        return s;
    }
%>
<%
    Throwable cause = exception;
    while (cause.getCause() != null)
    {
        cause = cause.getCause();
    }
    String path = "/";
    String message = cause.getMessage(); //e.g ."Division by zero error";
    String exceptionClassName = exception.getClass().getName(); // e.g. "EOverflow";
    String sourceFile = "$(sourceFile:C:\\website\\WebSite\\src\\FrobTheGrobber.java)";
    String sourceLine = "$(sourceLine:619)";
    String serverInfo = getServletContext().getServerInfo().trim(); //e.g. "Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34209"
    String javaVersion = System.getProperty("java.version");
    StringWriter sw = new StringWriter();
    exception.printStackTrace(new PrintWriter(sw));
    String stackTrace = sw.toString();
    StackTraceElement[] stes = exception.getStackTrace();
    if (stes.length > 0)
    {
        StackTraceElement st = stes[0];
        sourceFile = st.getFileName();
        sourceLine = Integer.valueOf(st.getLineNumber()).toString();
    }
%>
<html>
    <head>
        <title><%= htmlEncode(message)%></title>
        <meta name='viewport' content='width=device-width' />
        <style>
         body {
                font-family:'Verdana';
                font-weight:normal;
                font-size: .7em;
                color:black;
            }
         p {
                font-family:'Verdana';
                font-weight:normal;
                color:black;
                margin-top: -5px;
            }
         b {
                font-family:'Verdana';
                font-weight:bold;
                color:black;
                margin-top: -5px;
            }
         H1 {
                font-family:'Verdana';
                font-weight:normal;
                font-size:18pt;
                color:red;
            }
         H2 {
                font-family:'Verdana';
                font-weight:normal;
                font-size:14pt;
                color:maroon;
            }
         pre {
                font-family:'Consolas','Lucida Console',Monospace;
                font-size:11pt;
                margin:0;
                padding:0.5em;
                line-height:14pt;
            }
         .marker {
                font-weight: bold;
                color: black;
                text-decoration: none;
            }
         .version {
                color: gray;
            }
         .error {
                margin-bottom: 10px;
            }
         .expandable {
                text-decoration:underline;
                font-weight:bold;
                color:navy;
                cursor: grab;
            }
         @media screen and (max-width: 639px) {
                pre {
                    width: 440px;
                    overflow: auto;
                    white-space: pre-wrap;
                    word-wrap: break-word;
                }
         }
         @media screen and (max-width: 479px) {
                pre {
                    width: 280px;
                }
         }
        </style>
    </head>
    <body bgcolor='white'>
        <span><H1>Server Error in '<%=htmlEncode(path)%>' Application.<hr width=100% size=1 color=silver></H1>
            <h2> <i><%=htmlEncode(message)%></i> </h2></span>
      <font face='Arial, Helvetica, Geneva, SunSans-Regular, sans-serif'>
      <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
      <br><br>
        <b> Exception Details: </b><%=htmlEncode(exceptionClassName)%>: <%=htmlEncode(message)%><br><br>
        <br>
<!--
        <b> Source Error: </b>
        <table width=100% bgcolor='#ffffcc'>
            <tr>
                <td>
                    <code><pre>
                    </pre></code>
                </td>
            </tr>
        </table>
-->
        <b> Source File: </b> <%=htmlEncode(sourceFile)%><b>    Line: </b> <%=htmlEncode(sourceLine)%>
        <br><br>
        <b>Stack Trace:</b> <br><br>
        <table width=100% bgcolor='#ffffcc'>
            <tr>
                <td>
                    <code><pre>
<%=htmlEncode(stackTrace)%>
                    </pre></code>
                </td>
            </tr>
        </table>
        <br>
        <hr width=100% size=1 color=silver>
        <b>Version Information:</b> <%=htmlEncode(serverInfo)%>; Java Version: <%=htmlEncode(javaVersion)%>
        </font>
    </body>
</html>
And Bob's your uncle - a useful error page:
