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

前端 未结 7 2027
说谎
说谎 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:32

    Since Servlet 3.0, there's a HttpServletResponse#getStatus().

    So, if there's room for upgrading, upgrade to Servlet 3.0 (Tomcat 7, Glassfish 3, JBoss AS 6, etc) and you don't need a wrapper.

    chain.doFilter(request, response);
    int status = ((HttpServletResponse) response).getStatus();
    

提交回复
热议问题