在发送给客户端之前查看响应标头? [英] View response headers before they are sent to the client?

查看:220
本文介绍了在发送给客户端之前查看响应标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为学校写一个项目。我想能够在网页上显示Web服务器发送给客户端的响应头。我能够从HttpServletRequest读取请求头,并且能够将响应头写入HttpServletResponse没有问题。



有没有办法做到这一点?可以复制服务器要发送的内容吗?



我正在使用Eclipse Helios来开发具有POJO应用程序的JSP,并且正在使用运行在Debian Lenny上的Tomcat 5.5进行服务。



谢谢,



Ean

解决方案

你可以使用 Filter HttpServletResponseWrapper



覆盖三个 addXHeader(..)方法,方法如下:

  void addHeader(String name,String value){
super.addHeader(name,value);
getWriter()。write(name +:+ value);
}

然后,在过滤器

  chain.doFilter(request,new HeaderHttpServletResponseWrapper(response)); 

但是我会使用Firebug来检查标题。



看到这个问题(第二个答案)


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

解决方案

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)

这篇关于在发送给客户端之前查看响应标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆