Java 其实很强大。可以获取HTTP头的详细信息,做出更为细致的处理,如获得文件最后修改时间等。
代码:
void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Enumeration enum1 = req.getHeaderNames(); log.debug("-----------header----------------->"); while(enum1.hasMoreElements()){ String key = (String)enum1.nextElement(); String value = req.getHeader(key); log.debug(key + ":" + value); } log.debug("<-----------header-----------------"); }结果:
-----------header-----------------> Accept:*/* Referer:http://localhost:9080/UtanWeb/imgsys/main/regTempMgr.html Accept-Language:zh-cn Accept-Encoding:gzip, deflate If-Modified-Since:Thu, 15 Sep 2011 12:13:41 GMT User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Host:localhost:9080 Connection:Keep-Alive <-----------header-----------------