[java]代码库
package pm_cn.itcast.request;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RequestDemo2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 获得 客户机的 请求 的时候 带过来的请求头信息
String value = request.getHeader("Accept-Language");
System.out.println(" Accept-Language : " + value);
System.out.println("===================");
// 获得 所有的请求头的 信息 :
Enumeration<String> names = request.getHeaderNames();
while(names.hasMoreElements()){
String name = names.nextElement(); // 获得 每个头的 名称
// 获得头的 值
String value2 = request.getHeader(name);
System.out.println(name + ": " +value2 );
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}