是否有可能在tomcat中的过滤器的doFilter函数中恢复Referrer?

时间:2011-04-19 14:48:01

标签: java tomcat

我有一个过滤器来显示http请求标头:

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

我需要查看referer标题,但我不知道为什么过滤器不显示。 “我做错了什么?

1 个答案:

答案 0 :(得分:0)

如果将Tomcat放在吞下此标头的代理后面,就会发生这种情况。从Java / Tomcat方面无法解决此问题。你需要在代理方面解决它。

user-agent = Java/1.5.0_22令人怀疑。它是一个使用java.net.URLConnection或其他东西的本土代理/客户端吗?