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 ]