This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Filter Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Filter Question" Watch "Filter Question" New topic
Author

Filter Question

Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

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 guaranteed to be called before the 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 ServletRequest and ServletResponse objects that were passed into it.
G. A filter’s doFilter() may block further request processing.

I took this question from Head First SCWCD book.

The correct answers are ;

ADG

but I think the E is also correct ? Why E is not correct ?


blog: http://tunatore.wordpress.com
SCJP 6.0 + SCWCD 1.5
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

hi
in HFSJ some where it said it is not a need to doFilter() on the input FilterChain object within doFilter

hmm check out errata http://oreilly.com/catalog/errataunconfirmed.csp?isbn=9780596516680


Sudheer
SCWCD, SCJP 5
kiran mathew
Greenhorn

Joined: Jun 16, 2008
Posts: 16
It is not mandatory to call the next filter in the chain. The filter can decide whether to call the next filter in the chain.

For eg:
There are two different filters for authentication and authorisation. The authentication filter needs to call the authorisation filter only if the principal is authenticated.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

But answer E clearly states that is merely necessary if you want to make sure all filters are called. And since a filter cannot know how many more filters will follow, I agree that calling doFilter on the FilterChain object is the only way to ensure that all filters have a change to execute.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
kiran mathew
Greenhorn

Joined: Jun 16, 2008
Posts: 16
I think we can interpret the statement E in two ways

1) If we want to ensure that all filters have a chance to execute, a filter’s doFilter() method must call doFilter() on the input FilterChain object.

2) It is mandatory for a filter to call doFilter() on the input FilterChain object. This is to ensure that all filters have a chance to execute.

If we interpret it in the first way (1), the statement is true. If we interpret it in the second way(2), the statement is false. I think the person who made that question meant the second one.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
why people design question like this which has no similar comment by two people. is this a kind of abtract way of desiging a question


Thanks <br />Poonam Agarwal SCWCD 86%
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

hahahaha .....



 
Don't get me started about those stupid light bulbs.
 
subject: Filter Question