View response headers before they are sent to the client?
I am writing a project for school. I want to be able to display, on a web page, the response headers that the web server sent to the client. I am able to read request headers from HttpServletRequest and am able to write response headers to HttpServletResponse no problem.
Is there any way to do this? It is possible to make a co开发者_如何转开发py of what the server is about to send?
I am using Eclipse Helios to develop this JSP with POJOs application, and am using Tomcat 5.5 running on Debian Lenny to serve it.
Thanks,
Ean
You can use a Filter
and an HttpServletResponseWrapper
.
Override the three addXHeader(..)
methods with something like:
void addHeader(String name, String value) {
super.addHeader(name, value);
getWriter().write(name + " : " + value);
}
And then, in a Filter
:
chain.doFilter(request, new HeaderHttpServletResponseWrapper(response));
But I would use Firebug to check headers.
Or see this question (the 2nd answer)
You probably want to write a servlet filter which can intercept both the request and response before it gets sent.
精彩评论