To access all initialization parameters, the method ________ can be used, which returns an _________.
- getInitParameterNames(), Enumeration
- getInitParameters(), ArrayList
- getParameters(), Array
- getServletContext(), Enumeration
The correct method is getInitParameterNames(), which returns an Enumeration containing the names of the servlet's initialization parameters.
What is the best approach to maintain user sessions in a distributed web application environment?
- Database Session
- HTTP Session
- Hidden Form Fields
- URL Rewriting
The best approach to maintain user sessions in a distributed web application environment is to use HTTP Session. This allows for centralized session management across multiple servers.
Which method in a filter is responsible for cleaning up resources when the filter is taken out of service?
- destroy()
- doFilter()
- filterInit()
- init()
The destroy() method is responsible for cleaning up resources when the filter is taken out of service.
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.
How does a filter modify the response of a servlet or JSP in the filter chain?
- By modifying the request object
- By modifying the response object
- By replacing the servlet output
- By skipping the filter chain
A filter modifies the response by manipulating the response object in the filter chain. It can modify headers, content, or perform other operations on the response before it reaches the client.
In the context of filter configuration, what is the purpose of the tag in web.xml?
- Associates a filter with a servlet or URL pattern
- Defines filter initialization parameters
- Indicates the filter lifecycle
- Specifies the filter execution order
The tag in web.xml associates a filter with a servlet or URL pattern, specifying where the filter should be applied in the web application.
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.