File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getHeader()

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why option 4th is correct one.

What else could it be, given its method signature?
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
Firefox Browser Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic