我有一個過濾器來顯示HTTP請求頭:是否有可能在Tomcat中恢復過濾器的doFilter函數中的引用者?
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
Enumeration headers = req.getHeaderNames();
for (; headers.hasMoreElements();) {
String name = (String) headers.nextElement();
String value = req.getHeader(name);
LOGGER.info("- " + name + " = " + value);
}
chain.doFilter(request, response);
}
使用Firebug我可以看到下面的請求頭:
Host mydomain.com
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20100101 Firefox/4.0
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Referer http://mydomain.com/test/index.html
但過濾器只顯示我:
16:39:49,064 INFO RefererFilter:42 - - user-agent = Java/1.5.0_22
16:39:49,064 INFO RefererFilter:42 - - host = mydomain.com
16:39:49,064 INFO RefererFilter:42 - - accept = text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
16:39:49,064 INFO RefererFilter:42 - - connection = keep-alive
16:39:49,064 INFO RefererFilter:42 - - content-length = 0
我需要看看引用標題,但我不知道爲什麼過濾器不顯示。 「我做錯了什麼?
你怎麼測試呢?這是奇怪的是,你的標題顯示爲全小寫。 – 2011-04-19 15:03:34