Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 43028
76
  • 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).
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic