How do I use HttpServletRequest.getHeaderNames() to get the names of the headers of the HTTP request?

Alessandro A. Garbagnati

Well, it is that simple, this is java basics, and is based on the simple exanple that is provided in the Java API Documentation, for java.util.Enumeration. I strongly suggestion to read it when you have some time.


for (Enumeration enum=request.getHeaderNames(); enum.hasMoreElements();) {
    String headerName = (String)enum.nextElement();
    System.out.println("Name = " + headerName);
}

Remember, that HttpServletRequest is an interface, so you don't have to worry about the implementation, otherwise if you decide to switch to another Servlet Container, then you will not be able to do that...
That's why they are called interfaces.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact