Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

request.getHeader() return value ?

 
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,
 
Rancher
Posts: 43016
76
  • 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.
 
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: 43016
76
  • 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,
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


*/* means accept all application types and its sub types.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic