How can I get the HTTP status code out of a ServletResponse in a ServletFilter?

前端 未结 7 2026
说谎
说谎 2020-11-28 04:16

I\'m trying to report on every HTTP status code returned from my webapp. However the status code does not appear to be accessible via the ServletResponse, or even if I cast

7条回答
  •  北海茫月
    2020-11-28 04:24

    In addition to David's answer, you'll also want to override the reset method:

    @Override
    public void reset() {
        super.reset();
        this.httpStatus = SC_OK;
    }
    

    ... as well as the deprecated setStatus(int, String)

    @Override
    public void setStatus(int status, String string) {
        super.setStatus(status, string);
        this.httpStatus = status;
    }
    

提交回复
热议问题