相关疑难解决方法(0)

错误处理程序Servlet:如何获取异常原因

我在web.xml中配置了一个错误的servlet:

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/ExceptionHandler</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

对?

在我的(通用)servlet中:

doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        ...
        ...
    } catch (Exception e) {
        throw new ServletException("some mesage", e);
    }
}
Run Code Online (Sandbox Code Playgroud)

所以,"e"将是这种情况下的根本原因.

在我的ExceptionHandler类中,我有:

doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    throwable.getCause() //NULL
}
Run Code Online (Sandbox Code Playgroud)

这就是问题.throwable.getCause()为null.

java servlets exception-handling

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

exception-handling ×1

java ×1

servlets ×1