View response headers before they are sent to the client?

老子叫甜甜 提交于 2019-12-11 12:18:31

问题


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 copy 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


回答1:


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)




回答2:


You probably want to write a servlet filter which can intercept both the request and response before it gets sent.



来源:https://stackoverflow.com/questions/5214066/view-response-headers-before-they-are-sent-to-the-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!