• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

request.getHeader()

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why option 4th is correct one.


What else could it be, given its method signature?
 
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic