• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which about filters are true? Head first servlet question 5 page 735

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

i'm supicious about a question in Head First Servlets and JSP. This is the question :

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 ithe 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


  • Good answers are A, D and G.
    E is wrong because "-Option E is incorrect because calling doFilter() is not necessary if a filter wishes to block further request processing."

    That's where i'm not ok. If a filter "block further request processing" so we don't "ensure that all filters have a chance to execute".

    Do i miss something? Is my bad english playing trick on me?

    Thank you!
     
    Ranch Hand
    Posts: 453
    Google Web Toolkit Hibernate Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    i think its Filter's doFilter not FilterChain's doFilter()

    avi sinha
     
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.

    In doFilter method you don't need to call doFilter of filterChain object if you don't want to proceed with upcoming filters in the chain.
    For example if as per you filter logic there was some logical error in the data passed in the request and you want to forward or redirct to some error page rather than proceeding the request or processing the upcoming filters in the chain .

    SO Option E is incorrect.

    I wish I could help you .... Goood Luck
     
    Thibault Delor
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hassan Ebied, i totally agree on the fact that YOU CAN stop the processing of upcoming filters but that's not the questions or rather what i have understand. If i reword the answer E with my words that give :
    "If you really really want that all filters have a chance to execute, you have to call doFilter() on FilterChain"
    And so for me it's right, doFilters' goal is to proceed nexts filters! no?
     
    Hassan Ebied
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    And so for me it's right, doFilters' goal is to proceed nexts filters! no?.

    doFilter method goal is not actually to proceed with next filters , its mission in life is do some certain logic before proceeding the request by the container and everything is fine then it will call doFilter on filterChain object to let the container either to to proceed with the request of the queue of filters is empty or to select the next filter from the chain to be processed.
     
    Thibault Delor
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Hassan Ebied wrote:And so for me it's right, doFilters' goal is to proceed nexts filters! no?.

    doFilter method goal is not actually to proceed with next filters , its mission in life is do some certain logic before proceeding the request by the container and everything is fine then it will call doFilter on filterChain object to let the container either to to proceed with the request of the queue of filters is empty or to select the next filter from the chain to be processed.


    I spoke about dofilter method of FilterChain in this sentence :And so for me it's right, doFilters' goal is to proceed nexts filters! no?.
    When i said "next filters" it means "next filter if there's one, else the servlet"

    If you don't call dofilter method of FilterChain, next filters won't be executed, so we can say that in order to ensure that all filters have a chance to execute you must call doFilter() on the input FilterChain object, no???
     
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Same problem. I read this 15 times and I think it just should be read like this:

    A filter’s doFilter() method must DO X

    where:

    DO X is "call doFilter() on the input FilterChain object in order to ensure that all filters have a chance to execute"

    But not like this:

    A filter’s doFilter() method must DO X in order to ensure Y

    where:

    DO X is "call doFilter() on the input FilterChain object"
    Y is "that all filters have a chance to execute"

    It's the only way I can explain it to myself.
     
    Sheriff
    Posts: 67747
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    "Bad Boy Boogie", please check your private messages for an important administrative matter.
     
    Greenhorn
    Posts: 20
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think option E should be considered a correct answer.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic