package cn.itcast.web.request;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
@WebServlet("/requestdemo2")
public class requestdemo2 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取请求头数据
//获取请求头的名称
Enumeration headernames = req.getHeaderNames();
//2。遍历
while (headernames.hasMoreElements()){
String name = headernames.nextElement();
//根据名称获取请求头的值
String value = req.getHeader(name);
System.out.println(name+"-------"+value);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
}