jQuery in Action, 2nd edition*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes request.getHeader() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "request.getHeader()" Watch "request.getHeader()" New topic
Author

request.getHeader()

Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Assume that the following header is present in a request sent to a servlet:

Accept: image/gif, image/jpeg, image/bmp

What will be returned when the servlet code calls request.getHeader("Accept")? (from Entuware Mock)

1. A Header object containing, name as "Accept" and value as "image/gif".
2. A Header object containing, name as "Accept" and value as "image/gif, image/jpeg, image/bmp".
3. A String array containing "image/gif"".
4. A String containing "image/gif, image/jpeg, image/bmp".
5. A String array containing "image/gif", "image/jpeg", image/bmp".

why option 4th is correct one.
I guess The method HttpServletRequest.getHeaders() returns an Enumeration in which each comma separated value can be retrieved using Enumeration.nextElement().
not request.getHeader()??

Please correct me if I am wrong

Thanks in Advance


Thanks <br />Poonam Agarwal SCWCD 86%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41180
    
  45
why option 4th is correct one.

What else could it be, given its method signature?


Ping & DNS - my free Android networking tools app
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

you are wrong.

the method that return a enumeration is: getHeaderNames()

and in this question are using the method: getHeader(String name), that Returns the value of the specified request header as a String.

taken from the java documentation.

xD
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Milton,

getHeaders() and getHeaderNames() both return the java.util.Enumeration. Just have a look at the API

http://java.sun.com/j2ee/1.4/docs/api/index.html
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

you have to be very (what is the word) "cuidadoso" (spanish word, sorry).

The methods:

java.lang.String getHeader(java.lang.String name)
java.util.Enumeration getHeaders(java.lang.String name)


Are not the same, and in the question are asking about the method: getHeader(String).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.getHeader()
 
Similar Threads
request.getHeader() return value ?
Handling refresh browser using request.getHeader("Accept")
Handling Browser refresh
setting request header
case of multiple headers