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

${pageContext. request. header["Accept-Language"}

 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

On question 19 on page 314 of Charles Lyons' book is the following (I am typing this manually so typos are likely).


The answer says B and D are correct. There is no mention in the errata of this question.

I thinnk I disagree with B. For B to be true wouldn't getHeader() have to be a method on HttpServletRequest that takes no arguments and returns a MAP or a BEAN (which in turn would have a "Accept-Header" key or property)? There is no such method.

Anyway, I can't get it to work in Tomcat. I'd be interested to know if anyone else can.

Am I missing something perhaps?

Thanks!
John
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. B is not correct. And it does not work in tomcat. And you said it's not in the erata right?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right! That's the second mistake you've spotted this week; I'm embarrassed now

Actually, I don't know what I was thinking with that option... there might have been something deeply profound and it's a typo in the translation from my rough draft questions to the book. But if there was, I have no idea what it was now! There is also a missing } at the end of the line I notice.

So let's add this to the errata for the book:
On p.314, Q.19 says "(choose two)" and option B is missing a closing brace }.
Correction: It should read "(choose one)" and option B should have the closing } at the end of the line.

On p.319, the answer to Q.19 says B is a correct answer.
Correction: B is incorrect; D is the only correct answer. Explanation: pageContext.request is an object of type ServletRequest (and usually HttpServletRequest). But there is no zero-argument getHeader() method on that interface or class. Hence it cannot be searched using the [] operator.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On second thoughts, maybe this would be better:
On p.314, Q.19 option B reads: ${ pageContext.request.header["Accept-Language"]
Correction: It should read: ${ headerValues["Accept-Language"][0] }
Then the rest of the question and explanation can stay correct... do you know why?

I think I prefer that single alteration actually.
 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification and update Charles.

I must say though that I find your book is excellent as a final phase in my test preparation. It is definitely sharpening my skills for the test. I recommend it.

(PS: I seem to remember somewhere in the API one can retrieve a Map of headers, where the Map keys are the header names and the Map values are String arrays. But I can't remember where/how one retrieves that. )
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to remember somewhere in the API one can retrieve a Map of headers, where the Map keys are the header names and the Map values are String arrays.
If there is one, I can't find it! I trawled through all the API I could think of yesterday but to no avail. There is one for query string parameters, Map<String,String[]> ServletRequest.getParameterMap(), but not for headers. I do like it when the APIs are consistent!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic