当前页面: 开发资料首页 → JSP 专题 → 在一个filter中怎样得到一个http请求后的statusCode?
在一个filter中怎样得到一个http请求后的statusCode?
摘要: 在一个filter中怎样得到一个http请求后的statusCode?
要记录下每个请求页面的返回statusCode,就象apache日志里的200。
这个在一个filter中能不能取得到?
大家帮忙,谢拉。
UP!!!!!
顶
request对象里面就有了.
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);
}
}
当然可以取到! 在 filterChain.doFilter后面取一下不就行了?