Announcement Announcement Module
Collapse
No announcement yet.
Exception handling of exceptions thrown in jsp's Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception handling of exceptions thrown in jsp's

    Currently I use SimpleMappingExceptionResolver to show the users an appropriate error page and log the exception to a log file when an exception is thrown in a controller.

    The SimpleMappingExceptionResolver only handles exceptions thrown in controllers and not exceptions thrown when rendering a jsp.

    Is there a similar mechanism for jsp's? Ie. a mechanism allowing me to catch exceptions thrown while rendering a jsp, show the user an error page and log the exception to a log file?

    Best regards,
    Jørgen

  • #2
    OK, sorted it out myself. Had to add an isErrorPage="true" and after that I am able to access the exception:

    Code:
    <%@ page isErrorPage="true" import="org.apache.log4j.Logger"%>
    ...
    <%
       Logger.getLogger&#40;"exception.jsp"&#41;.error&#40;exception&#41;;
       Logger.getLogger&#40;"exception.jsp"&#41;.error&#40;exception.getCause&#40;&#41;&#41;;
    %>
    The problem now is that debugging shows me that a NullPointerException is thrown when rendering the jsp but the printout from the code above is org.apache.jasper.JasperException?!
    Is there a way to print out the root cause ie. the NullPointerException?

    Cheers from sunny Denmark,
    Jørgen

    Comment


    • #3
      Got the root cause by casting the Exception to a ServletException ie.:

      Code:
      <%
        if &#40;exception instanceof ServletException&#41; &#123;
          ServletException servletException = &#40;ServletException&#41; exception;
          Logger.getLogger&#40;"exception.jsp"&#41;.error&#40;servletException.getRootCause&#40;&#41;&#41;;
          Logger.getLogger&#40;"exception.jsp"&#41;.error&#40;servletException.getRootCause&#40;&#41;.getCause&#40;&#41;&#41;;
        &#125; else &#123;
          Logger.getLogger&#40;"exception.jsp"&#41;.error&#40;exception&#41;;
          Logger.getLogger&#40;"exception.jsp"&#41;.error&#40;exception.getCause&#40;&#41;&#41;;
        &#125;
      %>
      /Jørgen

      Comment

      Working...
      X