How to get the message in a custom error page (Tomcat)?

后端 未结 6 1955
刺人心
刺人心 2020-12-03 02:53

In JSPs, you may use response.sendError(int code, String message) to return a particular error code (eg 404 for not found) and a message as well. These messages

6条回答
  •  醉酒成梦
    2020-12-03 03:36

    The thing you want looks weird to me :). That said, I would do the following:

    1. Implement HttpResponseWrapper to wrap any other HttpResponse in this way:

      public class HttpResponseWrapper implements HttpResponse {
          private String errorMessage;
      ...
      
          @Override
          public void sendError(...) {
              
          }
      ...
      }
      
    2. Create a Filter and wrap any response in this

    3. Put filter on all requests and first in the chain

    4. In your error page check if response is instanceof HttpResponseWrapper

    5. Get your message

提交回复
热议问题