• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
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
 
Ranch Hand
Posts: 1512
  • 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?
 
Author
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
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
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!
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic