When multiple filters are defined, in what order are they executed?
- Alphabetical order
- Order of declaration in web.xml
- Order specified in filter-mapping
- Random order
Filters are executed in the order of declaration in the web.xml file. The order can be important when one filter's output is used as input to another filter in the chain.
How can a filter pass control to the next entity in the filter chain?
- chain.continueFiltering(request, response)
- chain.doFilter(request, response)
- filterChain.doFilter(request, response)
- filterChain.passControl(request, response)
To pass control to the next entity in the filter chain, the correct method is chain.doFilter(request, response). It invokes the next filter or the servlet in the chain.
What is the impact of a filter throwing an unchecked exception during the execution of its doFilter method?
- The container catches the exception and stops processing the request.
- The exception is ignored, and processing continues.
- The filter chain continues to the next filter or servlet.
- The response is sent without further processing.
If a filter throws an unchecked exception, the container catches it. However, the impact is that the processing of the request stops, and the response is not sent.
How can a filter be configured to process requests for specific servlets or URL patterns?
- By implementing the processOnly method in the filter.
- By setting the filter-url property in the deployment descriptor.
- By specifying servlet names or URL patterns in the filter's configuration.
- By using the @ProcessFor annotation in the filter code.
A filter can be configured to process requests for specific servlets or URL patterns by specifying servlet names or URL patterns in the filter's configuration in the deployment descriptor.
The __________ method is used to initialize the filter with configuration parameters.
- configure(FilterConfig config)
- init(FilterConfig config)
- initialize(FilterConfig config)
- setup(FilterConfig config)
The init(FilterConfig config) method is used to initialize the filter with configuration parameters.
What is the first method called when a filter is instantiated by the servlet container?
- destroy()
- doFilter()
- filterInit()
- init()
The filterInit() method is the first method called when a filter is instantiated by the servlet container. It is used for initialization purposes.
At which stage in the filter lifecycle can you perform actions based on the initialization parameters?
- destroy()
- doFilter()
- filterInit()
- init()
Actions based on initialization parameters can be performed in the doFilter() method, which is part of the filter lifecycle.
What is the correct order of method invocation in a filter's lifecycle?
- destroy(), init(), doFilter()
- doFilter(), init(), destroy()
- init(), destroy(), doFilter()
- init(), doFilter(), destroy()
The correct order of method invocation in a filter's lifecycle is init(), doFilter(), and destroy().
The __________ method of the FilterChain interface is used to invoke the next filter in the chain.
- doFilter()
- invokeNext()
- nextFilter()
- proceed()
The doFilter() method of the FilterChain interface is used to invoke the next filter in the chain.
The filter's __________ method is invoked for every request/response pair processed by the filter.
- doFilter()
- doProcessing()
- execute()
- process()
The filter's doFilter() method is invoked for every request/response pair processed by the filter.