How to grab uncaught exceptions in a Java servlet web application

后端 未结 3 1198
天涯浪人
天涯浪人 2021-01-01 21:15

Is there a standard way to catch uncaught exceptions that happen inside of a java servlet container like tomcat or Jetty? We run a lot of servlets that come from libraries

3条回答
  •  时光说笑
    2021-01-01 21:54

    In web.xml (the deployment descriptor) you can use the element to specify error pages by exception type or HTTP response status code. For example:

    
        404
        /error/404.html
    
    
        com.example.PebkacException
        /error/UserError.html
    
    

    For a NetBeans-centric description, mosey on over to Configuring Web Applications: Mapping Errors to Error Screens (The Java EE 6 Tutorial) (or see the Java EE 5 Tutorial's version).

提交回复
热议问题