• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

request.getHeader() return value ?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I was confused seeing the below question. (Enthuware mock test)


According to my understanding request.getHeader() returns the first value of header if it contains multiple values.
So why not the answer be Option C,

Can someone help me what does the request.getHeader() will actually returns.


Thanks,
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first sentence of the javadocs of HttpServletRequest.getHeader(String) explains what this method returns. This is easy to test in a real servlet container, by the way.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit Hetawal,

Yes. It should return the first header value. what you said is correct. you can try testing it.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Naveen Segu wrote:Yes. It should return the first header value. what you said is correct.


No; see my reply.
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried testing it, but all the headers had single values.
According to my understanding, i think the getHeader() will return the full string of header values i.e
if header :
"Test" = "value1,value2"

getHeader("Test") will give "value1,value2"


But if we have header as
"Test" = "value1"
"Test" = "value2"

getHeader("Test" will give "value1" ie the first value of the header.


Please correct me if i am wrong.

Thanks,
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit,
You can try with "Accept" header and see it !!
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my JSP i tried :

<%

System.out.println(request.getHeader("Accept"));

%>

Output : */*

Dont know what it means ?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


*/* means accept all application types and its sub types.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic