1、获取相关头信息
代码:
- Writer writer = response.getWriter();
- Enumeration<String> parameters = request.getHeaderNames();
- while (parameters.hasMoreElements()) {
- String parameter = parameters.nextElement();
- writer.write("header: " + parameter + ", content: " + request.getHeader(parameter)+"\n");
- writer.flush();
- }
- writer.close();
测试结果:
- header: Host, content: localhost:8080
- header: Connection, content: keep-alive
- header: Cache-Control, content: max-age=0
- header: User-Agent, content: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7
- header: Accept, content: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- header: Accept-Encoding, content: gzip,deflate,sdch
- header: Accept-Language, content: zh-CN,zh;q=0.8
- header: Accept-Charset, content: GBK,utf-8;q=0.7,*;q=0.3
本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/807338,如需转载请自行联系原作者