创建新项目请参考使用Eclipse创建我的第一个Servlet3.0
Enumeration代码如下
@WebServlet("/GetServlet")
public class GetServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Enumeration<String> headNames=request.getHeaderNames();
while(headNames.hasMoreElements()) {
//如果有更多的元素
String element=headNames.nextElement();
System.out.println(element+":"+request.getHeader(element));
}
}
}
控制台输出结果为: