HttpServletRequest.getHeaderNames()
returns Enumeration<String>
and HttpServletResponse.getHeaderNames()
returns a Collection<String>
.
Why this discrepancy?
getHeader. Returns the value of the specified request header as a String . If the request did not include a header of the specified name, this method returns null . If there are multiple headers with the same name, this method returns the first head in the request.
The getHeaderNames() of ServletRequest interface returns an Enumeration object, containing all the header names. The getHeader() method of ServletRequest interface returns the header value for the given header name. In this example, we are displaying all the header information of a request in the servlet page.
Enumeration was used in combination with Hashtable and Vector. HttpServletRequest had the getHeaderNames method since jdk 1.2 and has not since been altered.
However HttpServletResponse did not have the getHeaderNames method until jdk 6 and by that time Collection was obviously preferred over the legacy Enumeration.
The request method had implemented in java version 1.2. and while collected were comes from jdk 6.
so by the time improvement of java they have used two different things collection and enumeration.
if you see response header values there will be no change in them if we modified collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With