Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getHeader() return value ?

 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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,
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • 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.
 
Naveen Segu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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: 42969
73
  • Mark post as helpful
  • send pies
  • 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
  • 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,
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


*/* means accept all application types and its sub types.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic