• 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

EPractice Lab quiz 1 about filter instantiation

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Which of the following statements about the Filter mechanism are true?
[ Choose two ]

a. Two instances of the same filter class will be instantiated if there are two filter declarations for the same filter class.
b. For associating with groups of servlets and static content, the <servlet-name> element is used in mapping.
c. The last filter in <servlet-name> filter chain invokes the first filter in the <url-pattern> matching chain, or invokes the target Web resource if there are none.
d. Filters are not invoked for request dispatcher forward() and include() calls.
e. Filters are not invoked for request dispatcher forward() and include() calls.
f. The ServletConfig object can be used to read the initialization parameters for a filter.
g. Filters can be mapped using <servlet-name> or <url-pattern> element.

Choice A and Choice F are correct

The container instantiates exactly one instance of the Java class defining the filter per filter declaration in the deployment descriptor. Hence, two instances of the same filter class will be instantiated by the container if the developer makes two filter declarations for the same filter class. Hence choice A is correct.
Filters can be mapped using . servlet-name: To associate with a servlet name . url-pattern: To associate with a group of servlets and static resources Hence choice F is correct while choice B is incorrect.
The order that the container uses in building the chain of filters to be applied for a particular request URI is as follows:
1. First, the <url-pattern> matching filter mappings in the same order that these elements appear in the deployment descriptor.
2. Next, the <servlet-name> matching filter mappings in the same order that these elements appear in the deployment descriptor.
So the last filter in <url-pattern> filter chain invokes the first filter in the <servlet-name> matching chain, or invokes the target Web resource if there are none. Hence choice C is incorrect.
From the Servlets 2.4, it is possible to apply filters for resources invoked using the Request Dispatcher mechanism. The <dispatcher> element under <filter-mapping> provides this possibility. This element has four legal values: . FORWARD - Filter will be applied under RequestDispatcher.forward() calls .
REQUEST - Filter will be applied under ordinary client calls to the path or servlet.
INCLUDE - Filter will be applied under RequestDispatcher.include() calls.
ERROR - Filter will be applied under the error page mechanism. Hence choice D is incorrect. The names and values of these filter initialization parameters are available to the filter at runtime via the getInitParameter and getInitParameterNames methods on the filter's FilterConfig object and not via ServletConfig object. Hence choice E is incorrect.



But if the developer define the same name for two filters of the same class in DD, the application cannot be deployed.
I believe the correct answers are F and G.
For g, filters can be mapped using servlet-name and url pattern.
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic