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

前端 未结 7 2051
说谎
说谎 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:23

    Also need to include a wrapper for #sendRedirect, and it would be better to initialize status to '200' rather than '0'

    private int httpStatus = SC_OK;
    
    ...
    
    @Override
    public void sendRedirect(String location) throws IOException {
        httpStatus = SC_MOVED_TEMPORARILY;
        super.sendRedirect(location);
    }
    

提交回复
热议问题