This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Filter Question

 
Ranch Hand
Posts: 220
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 237
MyEclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kiran mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Tuna Töre
Ranch Hand
Posts: 220
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hahahaha .....



 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic