import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; public class MyServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EnumerationIn this example, we retrieve all the header names from a request using the getHeaderNames method, and then loop through the enumeration to get the value of each header using the getHeader method. Here, we print out the header names and their values to the console. This method is provided by the javax.servlet.http.HttpServletRequest class, which is a part of the Java Servlet API.headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); String headerValue = request.getHeader(headerName); System.out.println(headerName + " : " + headerValue); } } }