Handling 500 JRun servlet in ColdFusion

后端 未结 1 613
感情败类
感情败类 2021-01-21 23:36

All -

Is there a way to handle a 500 JRun servlet error in ColdFusion? I tried using cferror as well as using the site-wide handler in ColdFusion admin, but

相关标签:
1条回答
  • 2021-01-22 00:02

    The error that you are receiving is occurring at the JRun level. This type of error occurs before the ColdFusion error handler can trap it. You will need to create and assign an error handler at the JRun level. This can be accomplished by editing the web.xml file. (After making changes you will need to restart the JRun server.)

    Details can be found on this page, JRun 4 Programmers Guide - Servlet Programming Techniques - Handling exceptions.

    You can define how a web application handles errors using the error-page element in the WEB-INF/web.xml file. You can also define error handling for all web applications on the JRun server by adding error-page elements to the SERVER-INF/default-web.xml file.

    Handling HTTP error codes

    The error-code subelement of error-page in the web.xml file defines how JRun handles HTTP error codes generated during the processing of a servlet.

    You define an HTTP status code for the error-code element and then map the code to a destination in the location element. The following example maps the HTTP 500 (Internal Server Error) status code to the servererror.jsp page:

    <error-page>
        <error-code>500</error-code>
        <location>/error-pages/servererror.jsp</location>
    </error-page>
    

    The following table lists common error-related HTTP status codes:

    HTTP error code    Description
      400              Bad Request
      401              Unauthorized
      403              Forbidden
      404              Not Found
      408              Request Time-out
      500              Internal Server Error
    

    Accessing error attributes

    The HttpServletRequest and HttpServletResponse objects provide access to error information so that you can generate meaningful debugging information or targeted exception handlers. For more information and examples, see the link that I included above.

    JRun sets several attributes on the request object when an error is thrown. The following describes these attributes:

    • javax.servlet.error.status_code - Defines the HTTP error code, if applicable, as an int object. If the servlet throws an exception not related to HTTP, the status code is usually set to 500 (Internal Server Error).
    • javax.servlet.error.message - Returns the exception or error message.
    • javax.servlet.error.exception_type - Defines the type of exception.
    • javax.servlet.error.exception - Defines the actual exception thrown. You can use the printStackTrace method to view the stack trace of the exception.
    • javax.servlet.error.request_uri - Defines the request URI prior to the exception being thrown.
    0 讨论(0)
提交回复
热议问题