要记录下每个请求页面的返回statusCode,就象apache日志里的200。
这个在一个filter中能不能取得到?
大家帮忙,谢拉。

解决方案 »

  1.   

    It should be sth like this:public class StatusLogFilter extends BaseFilter implements Filter {
      public void doFilter(ServletRequest servletRequest,
                           ServletResponse servletResponse,
                           FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        ServletResponse respWrapper = new HttpServletResponseWrapper(response) {
          public void sendError(int status) throws IOException {
            // Do your log here
          }
          public void sendError(int status, String msg) throws IOException {
            // Do your log here
          }
          public void setStatus(int status) throws IOException {
            // Do your log here
          }
          public void setStatus(int status, String msg) throws IOException {
            // Do your log here
          }
        };
        filterChain.doFilter(servletRequest, respWrapper);
      }
    }
      

  2.   

    当然可以取到! 在 filterChain.doFilter后面取一下不就行了?