• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF: Filters and Wrappers question

 
Andrew Esse
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Head First book:

Question 5.
Which about filters are true? (choose all that apply)
A. Filters may be used to create request or response wrappers.
B. Wrappers may be used to create request or response filters.
C. Unlike servlets, all filter initialization code should be placed in the constructor since there is no init() method.
D. Filters support an initialization mechanism that includes an init() method that is quaranteed to be called before teh filter is used to handle requests.
E. A filter's doFilter() method must call DoFilter() on the input FilterChain object in order to ensure that all filters have a chance to execute.
F. When calling doFilter() on the input FilterChain, a filter's doFilter() method must pass in the same ServletReauest and ServletResponse objects that were passed into it.
G. A filter's doFilter() may block further request processing.

Book Answers:
A and G

The book states that 'Option C is incorrect because there is an init() method that should be used for filter initialization.'

If this is the case, then why wouldn't option D be true as well? How is the init() optional - 'should be used'?
[ September 23, 2004: Message edited by: Andrew Esse ]
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,

It looks like you found a mistake in the book. Congratulations!

The best place to submit errata for the book itself is this HF Servlets & JSP
page. By doing so, you'll help the authors to even improve the next print. Thank you for doing that.

Regards,

Phil.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I think that's a mistake (unless it's a trick question I'm too thick to see...)

It's obviously Phil's fault for not catching it during the review.

Thanks for the catch!

Kathy
 
Andrew Esse
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't sure because answer D is so concrete - guaranteed to be called, but the reason that C is wrong wasn't as concrete as D 'should be.' I thought maybe the init() didn't have to be called for some reason.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I confirm that D should be checked. Now Kathy, if nobody in the team catched it during the review this time, it's "simply" because the answers were corrected in the PDF we got. (A, D, G). I've no idea of who changed the answers afterwards, but that's what happened. Shame on him!
[ September 23, 2004: Message edited by: Philippe Maquet ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic