HttpServletRequest içinde Header bilgilerini almak için kullanılan methodlar aşağıdaki gibidir :
HttpServletRequest içinde Header bilgilerini almak için kullanılan methodlar javadoc açıklamaları aşağıdaki gibidir :
String getHeader(String name)
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 header name is case insensitive. You can use this method with any request header.
Parameters:
name - a String specifying the header name
Returns:
a String containing the value of the requested header, or null if the request does not have a header of that name
Enumeration<String>
Returns all the values of the specified request header as an Enumeration of String objects.
Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.
If the request did not include any headers of the specified name, this method returns an empty Enumeration. The header name is case insensitive. You can use this method with any request header.
Parameters:
name - a String specifying the header name
Returns:
an Enumeration containing the values of the requested header. If the request does not have any headers of that name return an empty enumeration. If the container does not allow access to header information, return null
Enumeration<String> getHeaders(String name)
Returns an enumeration of all the header names this request contains. If the request has no headers, this method returns an empty enumeration.
Some servlet containers do not allow servlets to access headers using this method, in which case this method returns null
name - a String specifying the header name
Returns:
an enumeration of all the header names sent with this request; if the request has no headers, an empty enumeration; if the servlet container does not allow servlets to use this method, null
Aşağıdaki kod gelen header bilgilerini ekrana basmaktadır :
Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Enumeration values = request.getHeaders(name); if (values != null) { while (values.hasMoreElements()) { String value = (String) values.nextElement(); System.out.println(name + ": " + value); } } }