站内搜索: 请输入搜索关键词

当前页面: 开发资料首页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后面取一下不就行了?


↑返回目录
前一篇: 谁有vss,提供下载地址也行,50分不少吧
后一篇: Hibernate高手请进!!!!!!!!!!